Let get_external_ip take a timeout.

master
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
1 changed files with 2 additions and 2 deletions

View File

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