fixed config download

This commit is contained in:
galgolan 2016-09-05 02:59:51 +03:00
parent 7b09d8759f
commit c4bf94acb1
1 changed files with 7 additions and 12 deletions

View File

@ -19,8 +19,11 @@ import os
import re import re
import sys import sys
import math import math
import gzip
from StringIO import StringIO
import signal import signal
import socket import socket
import requests
import timeit import timeit
import platform import platform
import threading import threading
@ -200,7 +203,7 @@ def build_user_agent():
'speedtest-cli/%s' % __version__ 'speedtest-cli/%s' % __version__
) )
user_agent = ' '.join(ua_tuple) user_agent = ' '.join(ua_tuple)
return user_agent return 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
def build_request(url, data=None, headers={}): def build_request(url, data=None, headers={}):
@ -375,21 +378,13 @@ def getConfig():
we are interested in we are interested in
""" """
request = build_request('://www.speedtest.net/speedtest-config.php') uh = requests.get('http://www.speedtest.net/speedtest-config.php', headers = {'user-agent':user_agent})
uh, e = catch_request(request)
if e:
print_('Could not retrieve speedtest.net configuration: %s' % e)
sys.exit(1)
configxml = [] configxml = []
while 1: configxml.append(uh.text)
configxml.append(uh.read(10240))
if len(configxml[-1]) == 0:
break
if int(uh.code) != 200:
return None
uh.close() uh.close()
try: try:
try: try:
#print_(configxml)
root = ET.fromstring(''.encode().join(configxml)) root = ET.fromstring(''.encode().join(configxml))
config = { config = {
'client': root.find('client').attrib, 'client': root.find('client').attrib,