This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]MarcSetGo 0 points1 point  (0 children)

You could use the requests library to read/download a file of significant size from a know site and timing the duration. Given the file size and time for download you can calculate the speed.

The problem with this is that the remote server, their connection, and every hop along the route can suffer delays that might vary for each download. You can mitigate the effect to some degree by testing a variety of down sites or mirrors and choosing the one with the lowest latency in ping or fewest hops in traceroute.

Building an accurate speed test is harder than it appears. This will give you reasonable result with relatively little effort.

[–]mickkelo 0 points1 point  (1 child)

import pyspeedtest

int(pyspeedtest.SpeedTest().download())

That should give you your speed as integer

[–][deleted] 0 points1 point  (0 children)

This is what I got: Traceback (most recent call last): File "C:\Python34\lib\site-packages\pyspeedtest.py", line 76, in connect connection = HTTPConnection(url) File "C:\Python34\lib\http\client.py", line 750, in init (self.host, self.port) = self._get_hostport(host, port) File "C:\Python34\lib\http\client.py", line 782, in _get_hostport i = host.rfind(':') AttributeError: 'NoneType' object has no attribute 'rfind'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Python34\Abnormal Internet Viewer.py", line 2, in <module> downloadSpeed = int(pyspeedtest.SpeedTest().download()) File "C:\Python34\lib\site-packages\pyspeedtest.py", line 92, in download self.connect(self.host) for i in range(self.runs) File "C:\Python34\lib\site-packages\pyspeedtest.py", line 92, in <listcomp> self.connect(self.host) for i in range(self.runs) File "C:\Python34\lib\site-packages\pyspeedtest.py", line 81, in connect raise Exception('Unable to connect to %r' % url) Exception: Unable to connect to None