Categories
python

Ubuntu 22.04 + Firefox + Selenium + Geckodriver: Connection refused

The Ubuntu 22.04 + Firefox with Selenium and Geckodriver problem is: selenium.common.exceptions.TimeoutException: Message: Connection refused (os error 111) An older firefox version was installed from source after looking at geckodriver’s supported platforms docs… Environment details: $ firefox –version Mozilla Firefox 89.0.2 $ geckodriver –version geckodriver 0.29.1 (970ef713fe58 2021-04-08 23:34 +0200) selenium 3.14.1 Example script: from […]

Categories
python

Python Performance: Checking a collection contains a value (Membership)

A common task in programming and development is finding items that exist already or recognising duplicates. This is done by checking membership of an element in a collection. Often a list is used as it is mutable (can be changed and items added to it) and it is suited for single items. However there are […]

Categories
python

Python ModuleNotFoundError

One of the classic problems when running a python script that imports another module is not being able to find the module. ModuleNotFoundError: No module named ‘xxx’ There are 2 fundamentals to remember. A python module is – simply – a file A Python package is a folder containing a __init__.py file. A folder of […]

Categories
python

Python: Check how long a HTTPX Request took to run?

To check the response time of a python httpx request, use the response.elapsed attribute. import httpx client = httpx.Client() response = client.get(‘https://stoicquotesapi.com/v1/api/quotes/random’) print(response.elapsed.total_seconds()) This will print out the response time: 1.334806 Again: response.elapsed.total_seconds())

Categories
python

Python: Print all modules and packages available on the python path

When working with python a ImportError or ModuleNotFoundError: No module named 'xxx' may arise. This error usually means that the script or python file you are running does not know about a module you are importing. How can we get a list of modules that are accessible? Using Sys Modules This gets all package modules […]