Friday, February 25, 2022

[SOLVED] Python requests.get() only responds if adding a time out

Issue

I just did a fresh Raspberry OS install and now I don't get a requests.get() response in Python for most pages, it just becomes stuck and does not respond (interestingly, the address from the example on https://www.w3schools.com/python/module_requests.asp works, but https://google.com doesn't). Surprisingly, with the argument timeout=n it works after about n seconds. However, fixing the bug by adding a time out or some extra code is not convenient, because I use some modules relying on requests.get and fixing them manually can't be the best solution. Does anybody know why adding a time out is necessary now? When I used the old Raspbian OS, the very same scripts on the same device just worked.

import requests

x = requests.get('https://w3schools.com/python/demopage.htm')

works,

import requests

x = requests.get('https://google.com')

doesn't - it takes forever and never returns.

import requests

x = requests.get('https://google.com', timeout=1)

returns after 1 second.


Solution

I think this had to do with some IPv6 problems - the timeout forced the usage of IPv4? Disabling IPv6 in the router menu did the job.



Answered By - DeepKling
Answer Checked By - Gilberto Lyons (WPSolving Admin)