Added gzip support:

This commit is contained in:
galgolan 2016-09-05 15:24:10 +03:00
parent 7b09d8759f
commit aff490beea
1 changed files with 13 additions and 11 deletions

View File

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