how to force python call to speedtest.py use secure servers

Question:

I’m calling speedtest.py from my python program in order to run a speed test.
After importing speedtest.py I create a speedtest object using

s = speedtest.Speedtest() 
servers = s.get_best_server()

then run upload/download tests.
This has been working, but recently it has been failing.
I found if I just ran speedtest from the cli, I’d get a 403 forbidden error.
I then read than Speedtest now requires the use of secure servers.
SO, if from the cli I type

speedtest --secure

it runs perfectly.

My question is:
How can I tell speedtest to use secure servers from my python program?

I’ve tried variations of

s = speedtest.Speedtest("secure") 

and

servers = s.get_best_server("secure")
Asked By: Shawn

||

Answers:

I haven’t used the Python API for speedtest-cli, but looking at the source, Speedtest() has a secure parameter which presumably makes it require secure servers. So you’d just need to specify it when instantiating the class:

s = speedtest.Speedtest(secure=True)

BTW, there is documentation for the Python API, but it’s super barebones and doesn’t mention this parameter at all.

Answered By: wjandrea
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.