安全中心 api 令牌请求

Security center api token request

这是我的代码:

    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 从安全中心获取令牌我需要发布内容类型和凭据,但像上面一样它不起作用:(

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

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

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