简体   繁体   English

在python中使用机械化时遇到HTTP错误400:错误的请求

[英]Met HTTP Error 400: Bad Request when using mechanize in python

I met a problem when I using mechanize in Python, look my codes first: 在Python中使用机械化时遇到了一个问题,请先查看代码:

>>> 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

the value of variable "s" is the url of website that I wanna visit, and then I created an Browser(), and then executed br.open(s), It's no error here, but after I assigning a cookiejar to the "br", continue to call open() method with right argument, the fault occurs, it shows "Bad Request". 变量“ s”的值是我要访问的网站的网址,然后创建了Browser(),然后执行br.open(s),在这里没有错误,但是在将cookiejar分配给“ br”,继续使用正确的参数调用open()方法,发生错误,并显示“错误请求”。

what should I do? 我该怎么办? many thanks! 非常感谢!

Try replicating this in a browser. 尝试在浏览器中复制它。 The website seems to have a certain requirement when it comes to cookies. 该网站对Cookie似乎有一定要求。 The site doesn't like the cookies you added, and therefore is blocking you with a 400 error. 该网站不喜欢您添加的Cookie,因此以400错误阻止您。

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

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