簡體   English   中英

在python中使用機械化時遇到HTTP錯誤400:錯誤的請求

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

在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

變量“ s”的值是我要訪問的網站的網址,然后創建了Browser(),然后執行br.open(s),在這里沒有錯誤,但是在將cookiejar分配給“ br”,繼續使用正確的參數調用open()方法,發生錯誤,並顯示“錯誤請求”。

我該怎么辦? 非常感謝!

嘗試在瀏覽器中復制它。 該網站對Cookie似乎有一定要求。 該網站不喜歡您添加的Cookie,因此以400錯誤阻止您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM