import urllib.request import urllib.parse url = 'https://passport.mingrisoft.com/Login/checkLogin' headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0'} data = bytes(urllib.parse.urlencode({'username': 'zhgy', 'password': 'zhgy@1993'}), encoding='utf-8') req = urllib.request.Request(url=url, data=data, method='POST', unverifiable=False) response = urllib.request.urlopen(req) print(response.read().decode())
以上是书中示例3.5的代码,因为书中提供的网址访问不了,所以我就使用了官网网址做测试,但是出现标题中错误
Traceback (most recent call last):
File "C:\Python\Python3.10.2\lib\urllib\request.py", line 1348, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "C:\Python\Python3.10.2\lib\http\client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Python\Python3.10.2\lib\http\client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Python\Python3.10.2\lib\http\client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Python\Python3.10.2\lib\http\client.py", line 1037, in _send_output
self.send(msg)
File "C:\Python\Python3.10.2\lib\http\client.py", line 975, in send
self.connect()
File "C:\Python\Python3.10.2\lib\http\client.py", line 1454, in connect
self.sock = self._context.wrap_socket(self.sock,
File "C:\Python\Python3.10.2\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "C:\Python\Python3.10.2\lib\ssl.py", line 1070, in _create
self.do_handshake()
File "C:\Python\Python3.10.2\lib\ssl.py", line 1341, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_SIGNATURE_TYPE] wrong signature type (_ssl.c:997)