gpt4 book ai didi

python - 遇到 HTTP 错误 400 : Bad Request when using mechanize in python

转载 作者:太空宇宙 更新时间:2023-11-04 06:36:27 26 4
gpt4 key购买 nike

我在 Python 中使用 mechanize 时遇到了一个问题,请先看我的代码:

>>> s
'http://www.renren.com'
>>> br=mechanize.Browser()
>>> br.open(s)
<response_seek_wrapper at 0x1012b15f0 whose wrapped object = <closeable_response at 0x1012b11b8 whose fp = <socket._fileobject object at 0x1012949d0>>>
>>> br.set_cookiejar(cj)
>>> br.open(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.7-intel/egg/mechanize/_mechanize.py", line 203, in open
File "build/bdist.macosx-10.7-intel/egg/mechanize/_mechanize.py", line 255, in _mech_open
mechanize._response.httperror_seek_wrapper: HTTP Error 400: Bad Request

变量“s”的值是我要访问的网站的url,然后我创建了一个Browser(),然后执行了br.open(s),这里没有错误,但是我分配了一个cookiejar到“br”,继续用正确的参数调用open()方法,出现错误,显示“Bad Request”。

我该怎么办?非常感谢!

最佳答案

尝试在浏览器中复制它。该网站似乎对cookies有一定的要求。该站点不喜欢您添加的 cookie,因此会以 400 错误阻止您。

关于python - 遇到 HTTP 错误 400 : Bad Request when using mechanize in python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10418473/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com