这是我的代码:
import requests
param = {
"username" : "login",
"password" : "password",
}
header = {
"content-type":"application/x-www-form-urlencoded"
}
r=requests.post("https://adres/rest/token", headers=header,params=param)
print(r.status_code)
这是此代码的结果:
Traceback (most recent call last):
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 849, in _validate_conn
conn.connect()
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 356, in connect
ssl_context=context)
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\ssl_.py", line 372, in ssl_wrap_socket
return context.wrap_socket(sock)
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 850, in _create
self.do_handshake()
File "C:\Users\holkam\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)
我正在尝试根据文档使用API和python3从安全中心获取令牌,我需要发布内容类型和凭据,但像上面一样,它不起作用:(
答案 0 :(得分:0)
您正在调用的API似乎具有自签名证书。在这种情况下可以使用的解决方法:
r=requests.post("https://adres/rest/token", headers=header,params=param, verify=False)
verify=False
不会检查SSL证书的有效性。