简体   繁体   English

Python Post 不发布任何内容

[英]Python Post doesnt post anything

I'm trying to make a program that will connect on a website using this code:我正在尝试制作一个程序,该程序将使用以下代码连接到网站:

import requests

url = "https://website/cours/login/index.php"


headers = {
    "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Mobile Safari/537.36"

}



brack = requests.post(url,headers = headers, data={"username":"e19****","password":"0****"})



content = brack.content
print(content)

the thing is that when im posting, nothing happens, like if I just did a GET.问题是当我发帖时,没有任何反应,就像我刚刚做了一个 GET。 There's no error when I run (200 OK).运行时没有错误(200 OK)。

Depending on the API definition, a POST request may not return a content.根据 API 定义,POST 请求可能不会返回内容。 Since you're getting a 200 response.因为你得到了 200 响应。 Most probably there's a json object that was returned with your POST request.很可能有一个json对象与您的 POST 请求一起返回。

Try this:尝试这个:

import requests

url = "https://website/cours/login/index.php"
headers = {
    "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Mobile Safari/537.36"

}


response = requests.post(url,headers=headers, 
           data={"username":"e19****","password":"0****"})


print(response.json())

Usually, if the POST request is expected to give a real-time/streaming ("instant") response to provide/return some data or content, then you might get an session/job ID where you can poll/fetch the completed job at a later time.通常,如果 POST 请求预期提供实时/流式(“即时”)响应以提供/返回一些数据或内容,那么您可能会获得一个会话/作业 ID,您可以在其中轮询/获取已完成的作业稍后。

These tutorial might be helpful:这些教程可能会有所帮助:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM