pyspeedtest无法找到测试s

2024-10-01 02:25:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用pyspeedtest获取连接的上载/下载速度,但我始终收到以下错误,我无法解决:

import pyspeedtest
st = pyspeedtest.SpeedTest()
st.download()

Exception: Cannot find a test server

欢迎提出任何建议/见解!在


Tags: testimportserverdownload错误exceptionfind建议
2条回答

如果您在pyspeedtest.py文件来自www.speedtest.net到c。速度测试.net在脚本v1.2.7的第186行。在

编辑:添加了如何使其工作的示例

您可以编辑pyspeedtest.py脚本(位于/usr/local/lib/python2.7/dist-packages/pyspeedtest.py在我的树莓皮3)上使用vi,例如:

sudo vi /usr/local/lib/python2.7/dist-packages/pyspeedtest.py

转到第186行并更改以下行:

^{pr2}$

收件人:

connection = self.connect('c.speedtest.net')

然后使用/usr/local/bin中的包装器运行pyspeedtest:

/usr/local/bin/pyspeedtest
Using server: speedtest.wilkes.net
Ping: 41 ms
Download speed: 46.06 Mbps
Upload speed: 11.58 Mbps

或者使用python解释器:

>>> import pyspeedtest
>>> st = pyspeedtest.SpeedTest()
>>> st.ping()
41.70024394989014
>>> st.download()
44821310.72337018
>>> st.upload()
14433296.732646577

该项目自2016年年中以来一直没有更新。最后一次更新是updated user-agent to prevent SpeedTest block...,如果你浏览一下代码,就会有[类似这样的注释]:(https://github.com/fopina/pyspeedtest/blob/master/pyspeedtest.py#L188

    # really contribute to speedtest.net OS statistics
    # maybe they won't block us again...

而且已经有bugs posted to GitHub关于这个项目没有工作,没有回应。在

所以,我的猜测是:这个项目可能违反了速度测试.net的服务条款,所以他们阻止了它。作者试图绕过这个街区,他们又封锁了它,作者放弃了。在这两年中,它用作备份的任何其他服务器要么阻止它,要么关闭(例如。,速度测试.serv.pt文件中提到的已不存在)。在

有一个a pull request from another user可以修复它,尽管它似乎没有通过CI测试。如果你想自己试试,你可以。在

但否则,你就不能使用这个库,也没有任何人可以帮助你使用它;它只是不起作用。你必须找到另一种方法来做同样的事情。在

相关问题 更多 >