Let get_external_ip take a timeout.

This commit is contained in:
voussoir 2021-11-13 01:20:13 -08:00
parent 53756662ad
commit e8a0b0a050
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -23,9 +23,9 @@ class NetworkToolsException(Exception):
class NoInternet(NetworkToolsException):
pass
def get_external_ip() -> str:
def get_external_ip(timeout=10) -> str:
url = 'https://voussoir.net/whatsmyip'
response = requests.get(url)
response = requests.get(url, timeout=timeout)
response.raise_for_status()
ip = response.text.strip()
return ip