Finally I kind of solved a longstanding problem with connecting to the REST API of Frappeframework/ERPNext instances via Python3 code.
Problem: I simply couldn’t connect. Tried every solution in the book (documentation). I find the documentation lacking, so I tried many, many, many, many, many permutations of parameters. Nothing worked.
Not even frappe-client.
But I could easily and perfectly get the expected responses using a browser, sending GET requests to the relevant instance in the LAN.
Yesterday I found the reason:
I was working on the connection code in Ubuntu hosted in WSL (Windows Subsystem for Linux) on a current Windows 11 Laptop.
The WSL on the Windows host doesn’t let the connections from my python code on Ubuntu inside WSL through to ports other than 80 (http) and 443 (https) – maybe more – of machines in the LAN, but the LAN instance(s) were on port 8000 and 8080. These were blocked somewhere between my code and the instance on the LAN.
Once I suspected a network problem (this took me a far too long time, because the network works fine for many things, so it was kind of out of my debugging range), a quick check with nc (netcat) confirmed the problem literally in a minute.
The confirmation test was easy: I just ran the code on the Windows host instead of on the Ubuntu from inside the WSL => It directly and immediately worked.
Ah, and the browser was not in WSL but on the Windows host. Once you understand the problem, it makes sense that it worked from the browser.
Maybe (probably) there is a network or firewall setting for the WSL (v2) VM or the Windows host itself. I didn’t find it for now (hints welcome), but wasn’t essential in my current projects, because I can switch to development on another host or even the Windows host.
This thing annoyed me for months, though, and hindered my progress in implementation work and building of implementation tools. I had many other aspects of framework and implementation to work on, so it wasn’t a killer, but I finally I really got enough of it and pushed far enough through the barrier to get past it.
So, be advised that Linux und WSL is not like a bare metal host with Linux.
There are additional network quirks you should suspect if something unexpectedly does not work involving a network connection.
Best, good luck, and have fun building useful stuff!