简单地发起一个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]
这是 HTTP 的状态码,说明 HTTP Server 返回了 400