Django x-www-form-urlencoded请求

Django x-www-form-urlencoded请求,django,Django,我正在尝试对django执行以下请求: 我尝试了以下代码,但不起作用: data = {'username': admin, 'password': 123, 'grant_type': 'password', 'client_id': 'xxxx', 'client_secret': 'xxxx'} headers = {'content-type': 'application/x-www-form-urlencoded'}

我正在尝试对django执行以下请求:

我尝试了以下代码,但不起作用:

data = {'username': admin, 
        'password': 123, 
        'grant_type': 'password',
        'client_id': 'xxxx',
        'client_secret': 'xxxx'}
headers = {'content-type': 'application/x-www-form-urlencoded'}
r = requests.post(url, data=data, headers=headers)

谢谢你的帮助

默认情况下为表单编码

通常,您希望发送一些表单编码的数据,很像HTML 形式。为此,只需向数据参数传递一个字典。你的 请求时,数据字典将自动进行表单编码 是制造的


谢谢,效果很好。因此,现在请求被正确执行,但在执行请求之后,我有以下错误:{'error':'unsupported_grant_type'}根据我所读的内容,如果数据未以头{“content type”:“application/x-www-form-urlencoded”}发送,则返回此错误。但是我发送了这个请求的标题没有?
>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.post("http://httpbin.org/post", data=payload)
>>> print r.text
{
  "origin": "179.13.100.4",
  "files": {},
  "form": {
    "key2": "value2",
    "key1": "value1"
  },
  "url": "http://httpbin.org/post",
  "args": {},
  "headers": {
    "Content-Length": "23",
    "Accept-Encoding": "identity, deflate, compress, gzip",
    "Accept": "*/*",
    "User-Agent": "python-requests/0.8.0",
    "Host": "127.0.0.1:7077",
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "data": ""
}