小编Wan*_*anu的帖子

urllib.error.HTTPError:HTTP错误400:错误请求

海兰!我试图打开网页,通常是在浏览器中打开,但是python只是发誓并且不想工作.

import urllib.request, urllib.error
f = urllib.request.urlopen('http://www.booking.com/reviewlist.html?cc1=tr;pagename=sapphire')
Run Code Online (Sandbox Code Playgroud)

另一种方式

import urllib.request, urllib.error
opener=urllib.request.build_opener()
f=opener.open('http://www.booking.com/reviewlist.html?cc1=tr;pagename=sapphi
re')
Run Code Online (Sandbox Code Playgroud)

这两个选项都会出现一种错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\urllib\request.py", line 461, in open
    response = meth(req, response)
  File "C:\Python34\lib\urllib\request.py", line 571, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python34\lib\urllib\request.py", line 493, in error
    result = self._call_chain(*args)
  File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain
    result = func(*args)
  File "C:\Python34\lib\urllib\request.py", line 676, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:\Python34\lib\urllib\request.py", line 461, in …
Run Code Online (Sandbox Code Playgroud)

python urllib urlopen python-3.x http-status-code-400

8
推荐指数
1
解决办法
2万
查看次数