Added gzip support:
This commit is contained in:
parent
7b09d8759f
commit
aff490beea
|
@ -24,6 +24,9 @@ import socket
|
|||
import timeit
|
||||
import platform
|
||||
import threading
|
||||
import urllib2
|
||||
import StringIO
|
||||
import gzip
|
||||
|
||||
__version__ = '0.3.4'
|
||||
|
||||
|
@ -375,19 +378,18 @@ def getConfig():
|
|||
we are interested in
|
||||
"""
|
||||
|
||||
request = build_request('://www.speedtest.net/speedtest-config.php')
|
||||
uh, e = catch_request(request)
|
||||
if e:
|
||||
print_('Could not retrieve speedtest.net configuration: %s' % e)
|
||||
sys.exit(1)
|
||||
request = build_request('://www.speedtest.net/speedtest-config.php', headers = {'user-agent':user_agent, 'accept-encoding': 'gzip'})
|
||||
uh = urllib2.build_opener()
|
||||
|
||||
response = uh.open(request)
|
||||
|
||||
text = gzip.GzipFile(fileobj=StringIO.StringIO(response.read())).read()
|
||||
configxml = []
|
||||
while 1:
|
||||
configxml.append(uh.read(10240))
|
||||
if len(configxml[-1]) == 0:
|
||||
break
|
||||
if int(uh.code) != 200:
|
||||
configxml.append(text)
|
||||
|
||||
if(int(response.code) != 200):
|
||||
return None
|
||||
uh.close()
|
||||
|
||||
try:
|
||||
try:
|
||||
root = ET.fromstring(''.encode().join(configxml))
|
||||
|
|
Loading…
Reference in New Issue