我的python版本是3.5,运行代码错误
来源:4-3 重构发送post请求

慕粉1223433931
2019-04-02
import requests
import urllib3
urllib3.disable_warnings()
url = 'https://coding.imooc.com/api/cate'
data = {
"apiname": "cate",
"cid": 0,
"secrect": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWUiOiI1MDUxNTQwIiwianRpIjoiMjc5OWUyMTNhOWY2NTJhNWJlMTE5MzU0MmUzODQwNDUiLCJkZXZpY2UiOiJtb2JpbGUifQ.EYHnj9qoAGX32SDiGhGj36FuU_4MY42TGrBASnfbJ7c",
"timestamp": "1554213141535",
"token": "17f5148f2d2ca10bdbb850dd0ab2171a",
"uid": "5051540",
}
def send_post(url,data,):
res = requests.post(url=url,data=data)
return res.json()
print(send_post(url,data))
D:\Python35\python.exe D:/Python/PythonRequests/ReuestsSctipt-Test-01.py
Traceback (most recent call last):
File “D:\Python35\lib\site-packages\urllib3\connectionpool.py”, line 594, in urlopen
self._prepare_proxy(conn)
File “D:\Python35\lib\site-packages\urllib3\connectionpool.py”, line 805, in prepare_proxy
conn.connect()
File “D:\Python35\lib\site-packages\urllib3\connection.py”, line 344, in connect
ssl_context=context)
File "D:\Python35\lib\site-packages\urllib3\util\ssl.py", line 344, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File “D:\Python35\lib\ssl.py”, line 377, in wrap_socket
_context=self)
File “D:\Python35\lib\ssl.py”, line 752, in init
self.do_handshake()
File “D:\Python35\lib\ssl.py”, line 988, in do_handshake
self._sslobj.do_handshake()
File “D:\Python35\lib\ssl.py”, line 633, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “D:\Python35\lib\site-packages\requests\adapters.py”, line 449, in send
timeout=timeout
File “D:\Python35\lib\site-packages\urllib3\connectionpool.py”, line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File “D:\Python35\lib\site-packages\urllib3\util\retry.py”, line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘coding.imooc.com’, port=443): Max retries exceeded with url: /api/cate (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)’),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “D:/Python/PythonRequests/ReuestsSctipt-Test-01.py”, line 19, in
print(send_post(url,data))
File “D:/Python/PythonRequests/ReuestsSctipt-Test-01.py”, line 16, in send_post
res = requests.post(url=url,data=data)
File “D:\Python35\lib\site-packages\requests\api.py”, line 116, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “D:\Python35\lib\site-packages\requests\api.py”, line 60, in request
return session.request(method=method, url=url, **kwargs)
File “D:\Python35\lib\site-packages\requests\sessions.py”, line 533, in request
resp = self.send(prep, **send_kwargs)
File “D:\Python35\lib\site-packages\requests\sessions.py”, line 646, in send
r = adapter.send(request, **kwargs)
File “D:\Python35\lib\site-packages\requests\adapters.py”, line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=‘coding.imooc.com’, port=443): Max retries exceeded with url: /api/cate (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)’),))
1回答
-
Mushishi
2019-04-02
这个是因为https的原因,后面补充了。你只需要在res = requests.post(url=url,data=data,verify=False)
00
相似问题