Why does my pico not open the site i give it

My pico throws a connection closed error when i try to open the site.
Here is a screenshot of my code. (I use a pico w)

1 Like

I don’t think it’s your code, I think it might be the website link points to nothing.

If I go to that page with my browser I get this.
Looks like it’s an old site? :frowning:

I have used this api in the past.
Maybe it will fit your needs.:man_shrugging:
Based on your code, I think it would be a drop in replacement.
https://time.now/developer/api/timezone/Australia/Sydney


Also have a look at the example in the urequest readme.
It has a killer setup that makes use of the more modern with: syntax.
The with keyword will fix your 'r' isn't defined error. :slight_smile:


Oh.. and welcome to the forums :partying_face:

It works now. Thanks a lot.
But I could not get the with working

1 Like

That’s ok :slight_smile:
But I think you should handle the r isn't defined error.

does this work?

# Init `req` and `res` as nothing
# Now they are guilty until proven innoscent
req = None
res = None

try:
    req = urequests.get(site)
    res = r.json()
except OSError as e:
    print("Request failed:", e)
finally: 
   # incase you haven't seen this before, 
   # finally will run no matter what happens in the try block.
   # you can be sure you close the door behind you which is proper
    if req:
        req.close()

if res:
   print(res)
else:
   print(":(")