简体   繁体   English

如何强制 python 调用 speedtest.py 使用安全服务器

[英]how to force python call to speedtest.py use secure servers

I'm calling speedtest.py from my python program in order to run a speed test.我从我的 python 程序调用 speedtest.py 以运行速度测试。 After importing speedtest.py I create a speedtest object using导入 speedtest.py 后,我使用创建了一个速度测试 object

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.我发现如果我只是从 cli 运行 speedtest,我会收到 403 forbidden 错误。 I then read than Speedtest now requires the use of secure servers.然后我读到 Speedtest 现在需要使用安全服务器。 SO, if from the cli I type所以,如果我从 cli 输入

speedtest --secure

it runs perfectly.它运行完美。

My question is: How can I tell speedtest to use secure servers from my python program?我的问题是:如何让 speedtest 使用我的 python 程序中的安全服务器?

I've tried variations of我试过的变体

s = speedtest.Speedtest("secure") 

and

servers = s.get_best_server("secure")

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.我没有将 Python API 用于speedtest-cli ,但查看源代码, Speedtest()有一个secure参数,这可能使其需要安全服务器。 So you'd just need to specify it when instantiating the class:所以你只需要在实例化 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.顺便说一句,有Python API 的文档,但它是超级准系统,根本没有提到这个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM