urllib2.HTTPError: HTTP Error 400: Bad Request

新手上路,请多包涵

简单地发起一个POST请求,但是报错了,麻烦大佬帮忙看一下

import sys
reload(sys)
sys.setdefaultencoding('utf8')

import urllib2
import urllib

import json
url = 'http://shuju.wdzj.com/plat-info-target.html'
data = urllib.urlencode({'type1': 19, 'type2': 20, 'status': 1, 'wdzjPlatId': 59})
request = urllib2.Request(url)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())    
response = opener.open(request,    data)
result = response.read()

报错如下:

Traceback (most recent call last):
  File "D:\bg\fullstack-data-engineer-master\data\get.py", line 30, in <module>
    response = opener.open(request,    data)
  File "D:\python\lib\urllib2.py", line 435, in open
    response = meth(req, response)
  File "D:\python\lib\urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "D:\python\lib\urllib2.py", line 467, in error
    result = self._call_chain(*args)
  File "D:\python\lib\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "D:\python\lib\urllib2.py", line 654, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "D:\python\lib\urllib2.py", line 435, in open
    response = meth(req, response)
  File "D:\python\lib\urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "D:\python\lib\urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "D:\python\lib\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "D:\python\lib\urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
[Finished in 0.7s]
阅读 3.3k
1 个回答

这是 HTTP 的状态码,说明 HTTP Server 返回了 400

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题