2

I met a problem when I using mechanize in Python, look my codes first:

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

what should I do? many thanks!

Simon
  • 63
  • 6

1 Answers1

0

Try replicating this in a browser. The website seems to have a certain requirement when it comes to cookies. The site doesn't like the cookies you added, and therefore is blocking you with a 400 error.

User
  • 23,729
  • 38
  • 124
  • 207