【问题标题】:Post Request in Python with a cookie set, but still not sending the datas correctly使用 cookie 集在 Python 中发布请求,但仍未正确发送数据
【发布时间】:2013-07-17 11:37:09
【问题描述】:

我是 Python 新手,但经过 3 小时的研究,我想我处理的问题还不错。 由于 cookie,我的 POST 请求绕过了登录墙,但它从未在页面上发布我想要的信息。 :(

这是我的代码:

import requests

url = "url"
headers = {
'Cookie': 'cookie',
'Content-Type': 'multipart/form-data',
'Accept': 'text/html,application/xhtml+xml',
'Accept-Language': 'en-gb,en;q=0.5',
'Accept-Encoding': 'gzip,deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive': '300',
'Connection': 'keep-alive',
'Content-Length': '41'
}

payload = {
'seo_page[keyword]': 'test',
'commit': 'Save'
}

p = requests.post(url, data=payload, headers=headers)

print p.text.encode('utf8')
print p.encoding
print p.headers

我认为,这正是我读过的 15 个主题中关于如何在 web 表单页面上发布数据的建议。

print p.text.encode('utf8') 给我的 HTML 没有我试图发送的数据。

有什么想法吗? :)

非常感谢!

【问题讨论】:

    标签: python cookies http-post


    【解决方案1】:

    一切顺利! POST 请求已正确设置,但由于边缘情况它仍然不接受数据: 我尝试发布的网站是在 Ruby on Rails 上开发的,它要求提供额外的身份验证令牌(开发是为了避免 CSRF 攻击)。

    干杯!

    【讨论】:

      猜你喜欢
      • 2018-05-14
      • 2014-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-21
      • 2012-07-28
      • 2022-11-28
      相关资源
      最近更新 更多