Urllib2.HTTPError: HTTPError 400: Bad Request

simply initiate a POST request, but the report is wrong. Please take a look at it

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

the error is as follows:

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]
Mar.18,2021

this is the status code of HTTP, indicating that HTTP Server returned 400

.
Menu