Forums

urllib3 Network is unreachable

Hello, I'm new to pythonanywhere and for my first script, I tried to use urllib3 and connect to a open api referenced in the whitelist:api.open-meteo.com no apikey is needed

my script runs well on my computer but it doesn't work on pythonanywhere:

Failed to establish a new connection: [Errno 101] Network is unreachable'))

My code:

import urllib3
urlBase="https://api.open-meteo.com/v1/forecast?latitude=48.853&longitude=2.349&current=temperature_2m"

http = urllib3.PoolManager()

response = http.request('GET', urlBase)

data=response.data

can't be simpler...

It looks like urllib is not handling the proxy correctly, so you may need to set it up -- see this help page. Alternatively use requests which will do it for you.

thx a lot

I hope it helped