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 diff --git a/speedtest_cli.py b/speedtest_cli.py index d93d5c3..b460bf4 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -21,6 +21,7 @@ import sys import math import signal import socket +import requests import timeit import platform import threading @@ -375,19 +376,12 @@ 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) - configxml = [] - while 1: - configxml.append(uh.read(10240)) - if len(configxml[-1]) == 0: - break - if int(uh.code) != 200: + uh = requests.get('http://www.speedtest.net/speedtest-config.php', headers = {'user-agent':user_agent}) + configxml = uh.text + + if(int(uh.status_code) != 200): return None - uh.close() + try: try: root = ET.fromstring(''.encode().join(configxml))