Python请求在POST请求中发送内容长度0

Python请求在POST请求中发送内容长度0,python,python-requests,Python,Python Requests,是真的应该是这样还是有什么问题 我这么做很简单,就像文件中提到的那样: response = requests.post(path, client_id=self.app_id, client_secret=self.app_secret, grant_type="client_credentials") response.request.headers的输出为 {'Content-Length': '0', 'User-Agent': 'python-requests/2.4.1 CPyth

是真的应该是这样还是有什么问题

我这么做很简单,就像文件中提到的那样:

response = requests.post(path, client_id=self.app_id, client_secret=self.app_secret, grant_type="client_credentials")
response.request.headers的输出为

{'Content-Length': '0', 'User-Agent': 'python-requests/2.4.1 CPython/2.7.5 Darwin/13.3.0', 'Connection': 'keep-alive', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate'}

我的错误是什么?

您没有发送任何帖子正文,因此内容长度为0。标题完全正确。如果要发送帖子正文,请设置
数据
关键字参数,和/或使用
文件
参数

您似乎试图将
应用程序/x-www-form-urlencoded
编码的数据作为关键字参数发送;将它们放在
数据
参数的字典中:

params = {
    'client_id': self.app_id,
    'client_secret': self.app_secret,
    'grant_type': "client_credentials"
}

response = requests.post(path, data=params)

请参阅Quickstart文档的。您没有发送任何帖子正文,因此内容长度为0。标题完全正确。如果要发送帖子正文,请设置
数据
关键字参数,和/或使用
文件
参数

您似乎试图将
应用程序/x-www-form-urlencoded
编码的数据作为关键字参数发送;将它们放在
数据
参数的字典中:

params = {
    'client_id': self.app_id,
    'client_secret': self.app_secret,
    'grant_type': "client_credentials"
}

response = requests.post(path, data=params)
请参阅Quickstart文档的第页