[fix] timeout on get_public_ip otherwish dyndns update is stucked

This commit is contained in:
Laurent Peuch 2018-06-30 11:14:54 +02:00
parent b46fb46768
commit 43b10298fc

View file

@ -21,7 +21,9 @@
import logging import logging
import re import re
import subprocess import subprocess
from urllib import urlopen import requests
from requests import ConnectionError
logger = logging.getLogger('yunohost.utils.network') logger = logging.getLogger('yunohost.utils.network')
@ -37,8 +39,8 @@ def get_public_ip(protocol=4):
raise ValueError("invalid protocol version") raise ValueError("invalid protocol version")
try: try:
return urlopen(url).read().strip() return requests.get(url, timeout=30).content.strip()
except IOError: except ConnectionError:
return None return None