简体   繁体   English

使用python的请求无效,但邮递员有效

[英]Request with python doesn't work but postman work

I work with Django (Python 3.5) and try request.post to one url but it returns error 405. In postman I chose post method and in body fill my data, the header is Content-Type :application/x-www-form-urlencoded and the result is true. 我使用Django(Python 3.5),并尝试将request.post放在一个网址上,但返回错误405。在邮递员中,我选择了post方法,然后在正文中填充数据,标题为Content-Type :application/x-www-form-urlencoded ,结果为true。

My python script is : 我的python脚本是:

import requests as r

login_data = {
   'UserName': 'uuuuu',
   'Password': 'pppppp'
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
a=r.post(url, data=login_data,headers=headers)

What can I do? 我能做什么?

In such a case you should look at your server, and printout request. 在这种情况下,您应该查看服务器和打印输出请求。 I would try with: 我会尝试:

import requests as r
import json 

login_data = {
    'UserName': 'uuuuu',
    'Password': 'pppppp'
}
headers = {"Content-Type": "application/x-www-form-urlencoded"} 
a=r.post(url, data=json.dumps(login_data), headers=headers)

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

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