From fc3ccb68024f19255aa058d371dbe3a067ae8e96 Mon Sep 17 00:00:00 2001 From: galgolan Date: Mon, 5 Sep 2016 03:04:33 +0300 Subject: [PATCH] cleaned code --- speedtest_cli.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index d748e6e..b460bf4 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -19,8 +19,6 @@ import os import re import sys import math -import gzip -from StringIO import StringIO import signal import socket import requests @@ -203,7 +201,7 @@ def build_user_agent(): 'speedtest-cli/%s' % __version__ ) user_agent = ' '.join(ua_tuple) - 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' + return user_agent def build_request(url, data=None, headers={}): @@ -379,12 +377,13 @@ def getConfig(): """ uh = requests.get('http://www.speedtest.net/speedtest-config.php', headers = {'user-agent':user_agent}) - configxml = [] - configxml.append(uh.text) - uh.close() + configxml = uh.text + + if(int(uh.status_code) != 200): + return None + try: try: - #print_(configxml) root = ET.fromstring(''.encode().join(configxml)) config = { 'client': root.find('client').attrib,