鍍金池/ 問答/Python/ urllib2.HTTPError: HTTP Error 400: Bad R

urllib2.HTTPError: HTTP Error 400: Bad Request

簡單地發(fā)起一個(gè)POST請(qǐng)求,但是報(bào)錯(cuò)了,麻煩大佬幫忙看一下

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

報(bào)錯(cuò)如下:

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]
回答
編輯回答
解夏

這是 HTTP 的狀態(tài)碼,說明 HTTP Server 返回了 400

2017年8月5日 06:20