I'm developing a Python application to check the external IP and save to a database, the problem is the following function:
def pega_ip(): ip = get('https://api.ipify.org').text return ip
Because it uses the get
method to receive content directly into a variable, when there is no internet connection, the error occurs:
File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 508, in send raise ConnectionError (e, request = request) requests.exceptions.ConnectionError: HTTPSConnectionPool (host = 'api.ipify.org', port = 443): Max retries exceeded with url: / (Caused by NewConnectionError (': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution ',))
I need to handle this problem because the program is terminated when this error occurs, I need that if the connection crashes it will continue executing and trying to access this url in order to get the external IP.