0

这是我的代码:

    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 从安全中心获取令牌,但是像上面一样它不起作用:(

4

1 回答 1

0

您调用的 API 似乎具有自签名证书。在这种情况下可以使用的解决方法:

r=requests.post("https://adres/rest/token", headers=header,params=param, verify=False) 

verify=False不会检查 SSL 证书的有效性。

于 2019-02-02T13:15:21.090 回答