Debian 10.9 speedtest-cli Workaround

Posted on Wed 14 April 2021 in Debian

What Is Wrong...

A command line version of Speedtest.net (speedtest-cli) used to work under previous versions of Debian 10. However, when I tried it on 10.9, it is broken and gives the error:

Retrieving speedtest.net configuration...
Traceback (most recent call last):
  File "/usr/bin/speedtest-cli", line 11, in <module>
    load_entry_point('speedtest-cli==2.0.2', 'console_scripts', 'speedtest-cli')()
  File "/usr/lib/python3/dist-packages/speedtest.py", line 1887, in main
    shell()
  File "/usr/lib/python3/dist-packages/speedtest.py", line 1783, in shell
    secure=args.secure
  File "/usr/lib/python3/dist-packages/speedtest.py", line 1027, in __init__
    self.get_config()
  File "/usr/lib/python3/dist-packages/speedtest.py", line 1113, in get_config
    map(int, server_config['ignoreids'].split(','))
ValueError: invalid literal for int() with base 10: ''

The Workaround

First of all, frome the command line, uninstall speedtest-cli:

% sudo apt purge speedtest-cli

Second, create a directory for the new one. I like to keep my Python scripts in the src folder.

% mkdir -p ~/src/speedtest
% cd ~/src/speedtest

Next, make sure that you have the python3-venv package installed:

% sudo apt install python3-venv

Finally, issue the following commands:

% python3 -m venv venv
% source venv/bin/activate
(venv) % python -m pip install --upgrade pip setuptools

Cache entry deserialization failed, entry ignored
Collecting pip
  Using cached https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl
Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/ae/42/2876a3a136f8bfa9bd703518441c8db78ff1eeaddf174baa85c083c1fd15/setuptools-56.0.0-py3-none-any.whl
Installing collected packages: pip, setuptools
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
  Found existing installation: setuptools 40.8.0
    Uninstalling setuptools-40.8.0:
      Successfully uninstalled setuptools-40.8.0
Successfully installed pip-21.0.1 setuptools-56.0.0

(venv) % python -m pip install speedtest-cli

Collecting speedtest-cli
  Using cached speedtest_cli-2.1.3-py2.py3-none-any.whl (23 kB)
Installing collected packages: speedtest-cli
Successfully installed speedtest-cli-2.1.3

Now, you can run the speedtest-cli command to get your Speedtest.net speeds. If you're using zsh, you may need to issue the rehash command for the new command to be found.

How To Keep Using The Workaround

It is normal, after this, to have a command not found error when running speedtest-cli. This is because the Python3 virtual environment has not been setup. To fix this, issue the following command:

% source ~/src/speedtest/venv/bin/activate

It will work after that. When you are done using speedtest-cli you can stop using the Python3 virtual environment by issuing the deactivate command.