Add some debugging for failed http requests using catch_request
This commit is contained in:
parent
aef4a78831
commit
ffd2c7f963
|
@ -201,9 +201,10 @@ def catch_request(request):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
uh = urlopen(request)
|
uh = urlopen(request)
|
||||||
return uh
|
return uh, False
|
||||||
except (HTTPError, URLError, socket.error):
|
except (HTTPError, URLError, socket.error):
|
||||||
return False
|
e = sys.exc_info()[1]
|
||||||
|
return None, e
|
||||||
|
|
||||||
|
|
||||||
class FileGetter(threading.Thread):
|
class FileGetter(threading.Thread):
|
||||||
|
@ -349,9 +350,9 @@ def getConfig():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request = build_request('https://www.speedtest.net/speedtest-config.php')
|
request = build_request('https://www.speedtest.net/speedtest-config.php')
|
||||||
uh = catch_request(request)
|
uh, e = catch_request(request)
|
||||||
if uh is False:
|
if e:
|
||||||
print_('Could not retrieve speedtest.net configuration')
|
print_('Could not retrieve speedtest.net configuration: %s' % e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
configxml = []
|
configxml = []
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -393,12 +394,14 @@ def closestServers(client, all=False):
|
||||||
'https://www.speedtest.net/speedtest-servers-static.php',
|
'https://www.speedtest.net/speedtest-servers-static.php',
|
||||||
'http://c.speedtest.net/speedtest-servers-static.php',
|
'http://c.speedtest.net/speedtest-servers-static.php',
|
||||||
]
|
]
|
||||||
|
errors = []
|
||||||
servers = {}
|
servers = {}
|
||||||
for url in urls:
|
for url in urls:
|
||||||
try:
|
try:
|
||||||
request = build_request(url)
|
request = build_request(url)
|
||||||
uh = catch_request(request)
|
uh, e = catch_request(request)
|
||||||
if uh is False:
|
if e:
|
||||||
|
errors.append('%s' % e)
|
||||||
raise SpeedtestCliServerListError
|
raise SpeedtestCliServerListError
|
||||||
serversxml = []
|
serversxml = []
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -443,7 +446,8 @@ def closestServers(client, all=False):
|
||||||
break
|
break
|
||||||
|
|
||||||
if not servers:
|
if not servers:
|
||||||
print_('Failed to retrieve list of speedtest.net servers')
|
print_('Failed to retrieve list of speedtest.net servers:\n\n %s' %
|
||||||
|
'\n'.join(errors))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
closest = []
|
closest = []
|
||||||
|
@ -739,9 +743,9 @@ def speedtest():
|
||||||
request = build_request('https://www.speedtest.net/api/api.php',
|
request = build_request('https://www.speedtest.net/api/api.php',
|
||||||
data='&'.join(apiData).encode(),
|
data='&'.join(apiData).encode(),
|
||||||
headers=headers)
|
headers=headers)
|
||||||
f = catch_request(request)
|
f, e = catch_request(request)
|
||||||
if f is False:
|
if e:
|
||||||
print_('Could not submit results to speedtest.net')
|
print_('Could not submit results to speedtest.net: %s' % e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
response = f.read()
|
response = f.read()
|
||||||
code = f.code
|
code = f.code
|
||||||
|
|
Loading…
Reference in New Issue