Skip to content

Commit 49d305f

Browse files
committed
#533 - use requests library to check for connection
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 26387e8 commit 49d305f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/attributecode/util.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,20 +287,24 @@ def load_json(location):
287287

288288

289289
# FIXME: rename to is_online: BUT do we really need this at all????
290+
# This is needed to check for the network connection when user wants to fetch
291+
# the licenses from DJE/LicenseDB
290292
def have_network_connection():
291293
"""
292294
Return True if an HTTP connection to some public web site is possible.
293295
"""
294-
import socket
295-
import http.client as httplib
296+
import requests
297+
298+
url = "https://scancode-licensedb.aboutcode.org/"
296299

297-
http_connection = httplib.HTTPConnection('dejacode.org', timeout=10) # NOQA
298300
try:
299-
http_connection.connect()
300-
except socket.error:
301+
response = requests.get(url)
302+
if response.status_code == 200:
303+
return True
304+
else:
305+
return False
306+
except requests.exceptions.RequestException:
301307
return False
302-
else:
303-
return True
304308

305309

306310
def extract_zip(location):

0 commit comments

Comments
 (0)