Using requests with PyScript
Python on the browser is a little different than standard CPython running on a local system due to how the web (browsers) work. For this reason requests (and other libraries that work via sockets) don't work out of the box. :(
Luckily, there's a quick fix for it!
Thanks to github user koenvo and their package pyodide-http we can now easily "patch" requests and make it work. All we need to do is add the following commands to our python code:
import pyodide_http
pyodide_http.patch_all()
After that, all we need to do is just use requests as usual.
To see it working, click on this button to get the list of PyScript maintainers directly from Github.