From c4bf94acb169192376d0189bc9ce6530e3be5690 Mon Sep 17 00:00:00 2001 From: galgolan Date: Mon, 5 Sep 2016 02:59:51 +0300 Subject: [PATCH 1/3] fixed config download --- speedtest_cli.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index d93d5c3..d748e6e 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -19,8 +19,11 @@ import os import re import sys import math +import gzip +from StringIO import StringIO import signal import socket +import requests import timeit import platform import threading @@ -200,7 +203,7 @@ def build_user_agent(): 'speedtest-cli/%s' % __version__ ) 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={}): @@ -375,21 +378,13 @@ 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) + uh = requests.get('http://www.speedtest.net/speedtest-config.php', headers = {'user-agent':user_agent}) configxml = [] - while 1: - configxml.append(uh.read(10240)) - if len(configxml[-1]) == 0: - break - if int(uh.code) != 200: - return None + configxml.append(uh.text) uh.close() try: try: + #print_(configxml) root = ET.fromstring(''.encode().join(configxml)) config = { 'client': root.find('client').attrib, From fc3ccb68024f19255aa058d371dbe3a067ae8e96 Mon Sep 17 00:00:00 2001 From: galgolan Date: Mon, 5 Sep 2016 03:04:33 +0300 Subject: [PATCH 2/3] 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, From 0bcd8591eb1d0472c0f85fb09bfec08d3e5f5913 Mon Sep 17 00:00:00 2001 From: galgolan Date: Mon, 5 Sep 2016 03:29:07 +0300 Subject: [PATCH 3/3] fixed CI --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e8b3a20..30d6d34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ env: - TOXENV=flake8 install: - - if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py31)") != 0 ]]; then pip install virtualenv==1.7.2 tox==1.3; fi; - - if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py31)") == 0 ]]; then pip install tox; fi; + - if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py31)") != 0 ]]; then pip install virtualenv==1.7.2 tox==1.3 requests; fi; + - if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py31)") == 0 ]]; then pip install tox requests; fi; script: - tox