python发送带头部的post请求出错是怎么回事
1个回答
展开全部
urlopen的参数到底怎么传递可以看看手册
楼下几位的回答是不准确的,错在参数要加上键,urllib2.open(url,data=data,headers=header)类似这样的
我想发送请求带上 headers 头部,请问为什么报错了?
Traceback (most recent call last):
File "D:\python\get-email-by-tieba.py", line 49, in <module>
main()
File "D:\python\get-email-by-tieba.py", line 6, in main
getThreadByTid()
File "D:\python\get-email-by-tieba.py", line 36, in getThreadByTid
req = urllib2.urlopen(url, post_data, headers)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 391, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 409, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 369, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1173, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1142, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "C:\Python27\lib\httplib.py", line 946, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 987, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 940, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 803, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 755, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 736, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 557, in create_connection
sock.settimeout(timeout)
File "C:\Python27\lib\socket.py", line 222, in meth
return getattr(self._sock,name)(*args)
楼下几位的回答是不准确的,错在参数要加上键,urllib2.open(url,data=data,headers=header)类似这样的
我想发送请求带上 headers 头部,请问为什么报错了?
Traceback (most recent call last):
File "D:\python\get-email-by-tieba.py", line 49, in <module>
main()
File "D:\python\get-email-by-tieba.py", line 6, in main
getThreadByTid()
File "D:\python\get-email-by-tieba.py", line 36, in getThreadByTid
req = urllib2.urlopen(url, post_data, headers)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 391, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 409, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 369, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1173, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1142, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "C:\Python27\lib\httplib.py", line 946, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 987, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 940, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 803, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 755, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 736, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 557, in create_connection
sock.settimeout(timeout)
File "C:\Python27\lib\socket.py", line 222, in meth
return getattr(self._sock,name)(*args)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询