🍍 Ubuntu上speedtest报错问题解决方法

Uncle WANG
2021-05-27 / 0 评论 / 31 阅读 / 正在检测是否收录...

ubuntu.jpeg

最近连续在ubuntu的18和20上安装speedtest后,执行speedtest都会提示一个错误信息:

Retrieving speedtest.net configuration...
Traceback (most recent call last):
File "/usr/bin/speedtest", line 11, in

load_entry_point('speedtest-cli==2.0.0', 'console_scripts', 'speedtest')()

File "/usr/lib/python3/dist-packages/speedtest.py", line 1832, in main

shell()

File "/usr/lib/python3/dist-packages/speedtest.py", line 1729, in shell

secure=args.secure

File "/usr/lib/python3/dist-packages/speedtest.py", line 1009, in init

self.get_config()

File "/usr/lib/python3/dist-packages/speedtest.py", line 1081, in get_config

map(int, server_config['ignoreids'].split(','))

ValueError: invalid literal for int() with base 10: ''

在网上找了一下,找到了答案:

From this speedtest-cli Pull Request, I gather the speedtest site have changed something in the response their API gives out. Looking at the first commit in the PR, you just need to modify a single line in speedtest.py.

If you're in Ubuntu or similar, and you have the file in the location shown in your output, you can fix it with:

Backup original code

sudo gzip -k9 /usr/lib/python3/dist-packages/speedtest.py

Make the line substitution

sed -i "s/^ map(int, server_config['ignoreids'].split(','))$/ map(int, (server_config['ignoreids'].split(',') if len(server_config['ignoreids']) else []) )/" /usr/lib/python3/dist-packages/speedtest.py
EDIT: the final patch is at https://github.com/sivel/speedtest-cli/commit/cadc68, and published in v2.1.3. It's too complex for a simple one-line sed command, but you could still apply it yourself manually. Or you could try downloading that version of the speedtest.py file yourself:

sudo gzip -k9 /usr/lib/python3/dist-packages/speedtest.py

sudo wget https://raw.githubusercontent.com/sivel/speedtest-cli/v2.1.3/speedtest.py \
-O /usr/lib/python3/dist-packages/speedtest.py
(Again, you should double-check the location of the speedtest.py file. The above location seems to be common for Ubuntu, but not across all versions of Unix/Linux.)

大意是最新的后台api有改动,导致前台报错,可以重新下载补丁文件进行修复:
`[email protected]:~# sudo gzip -k9 /usr/lib/python3/dist-packages/speedtest.py
[email protected]:~# sudo wget https://raw.githubusercontent.com/sivel/speedtest-cli/v2.1.3/speedtest.py -O /usr/lib/python3/dist-packages/speedtest.py`

执行以上两句即可进行修复,就正常了!

[email protected]:~# speedtest
Retrieving speedtest.net configuration...
Testing from Oracle Cloud (158.101.xx.xx)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by i3D.net (Tokyo) [45.90 km]: 2.065 ms
Testing download speed................................................................................
Download: 1146.54 Mbit/s
Testing upload speed......................................................................................................
Upload: 1222.96 Mbit/s
0

评论 (0)

取消