Wrote a small program, a simple test HTTPBasicAuthorization based REST API, the results of the program on the Windows machine error:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)
Error reporting on Linux machines:
"bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)"
The small procedure is as follows:
#!/bin/python
import requests
from requests.auth import HTTPBasicAuth
from pprint import pprint
my_url = 'https://192.168.12.34/nodes'
def main():
try:
r = requests.get(my_url,
auth=HTTPBasicAuth('username', 'passw0rd'))
pprint(r.status_code)
pprint(r.json())
except Exception as ex:
print("Exception: {ex}".format(ex=ex))
if __name__ == '__main__':
main()
The solution, it turns out, is to add verify=False to the parameters of the GET function
The root cause is that the certificate given by the site under test is considered questionable, so verify=False is required to pass the error.
, however, is not enough, because with verify=False, a large section of warning is printed out for each connection, indicating that the connection is secure. How can you disable this message if it is secured?Add a sentence to: requests. Packages. Urllib3. Disable_warnings ()
final code is as follows:
#!/bin/python
import requests
from requests.auth import HTTPBasicAuth
from pprint import pprint
my_url = 'https://192.168.12.34/nodes'
def main():
try:
requests.packages.urllib3.disable_warnings()
r = requests.get(my_url,
auth=HTTPBasicAuth('username', 'passw0rd'),
verify=False)
pprint(r.status_code)
pprint(r.json())
except Exception as ex:
print("Exception: {ex}".format(ex=ex))
if __name__ == '__main__':
main()
div>