使用请求模块在python中发布数据并添加标头

时间:2015-03-30 08:44:17

标签: python session http-post python-requests

我想将我的数据发布到网址但不起作用。我在python中尝试的是:(script.py)

session=requests.Session()
headers={'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0', 'Content-Type':'application/x-www-form-urlencoded'}
session.headers.update(headers)
post_data={'login':'login', 'username':'user', 'password':'password'}
post_response=session.post(url='https://website.com', data=post_data)
print post_response.content
sys.exit()

当我想以这种方式运行脚本时:

python script.py | w3m -T text/html

它返回错误:

Your browser is the problem. please use firefox or chrome or ...

我的代码有什么问题?

0 个答案:

没有答案