|
利用cookie模拟网站登录时增加headers 就报错
Traceback (most recent call last):
line 56, in <module>
resp**e = opener.open(url,post_data,headers)
TypeError: a float is required
源代码:
import urllib
import urllib2
import cookielib
cookie = cookielib.MozillaCookieJar()
handler =urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
headers = {
'Host':'www.santostang.com',
'User-Agent':'Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0',
'Referer':'http://www.santostang.com/wp-login.php',
'Origin':'http://www.santostang.com/',
'Connnection':'keep-alive'
}
post_data = urllib.urlencode({
'log':'test',
'pwd':'a12345',
'rememberme':'forever',
'redirect_to':'http://www.santostang.com/wp-admin/',
'testcookie':'1'
})
url = 'http://www.santostang.com/wp-login.php'
resp**e = opener.open(url,post_data,headers)
print(resp**e.read())
错误信息:
Traceback (most recent call last):
line 56, in <module>
resp**e = opener.open(url,post_data,headers)
File "C:\Python27\lib\urllib2.py", line 429, in open
resp**e = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 447, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 407, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1228, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1195, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "C:\Python27\lib\httplib.py", line 1042, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1082, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 1038, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 882, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 844, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 821, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 563, in create_connection
sock.settimeout(timeout)
File "C:\Python27\lib\socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
TypeError: a float is required
|
|