0

I tried up to day to get requests working on micropython, tried installing libraries and everything. I use thonny IDE. what can i do?

Error:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "urequests.py", line 184, in post
  File "urequests.py", line 76, in request
OSError: -202

Code:

import urequests
response = urequests.get('http://pastebin.com/raw/4309d09')

Tried installing external libraries like 'micropython-urequests' etc

3
  • this won't fix it but you want to make sure you use https and not http if you are transferring sensitive data that you don't want a man in the middle to read. Commented Jun 27, 2023 at 18:30
  • Debugging 101, make sure the content that you try to access is available. I try your URL, and got 404 page not found. So how can you get anything if it doesn't exist? Commented Jun 28, 2023 at 1:58
  • My url is fake :), I think its obvious that i would know whether it works or not. Commented Jun 28, 2023 at 12:48

1 Answer 1

0

you did not connect your board to wifi before requesting data from internet!

import network
import urequests

# Connect to network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
 
# Fill in your network name (SSID) and password here:
ssid = 'MyWIFI'
password = 'SuperSecretPassword'
wlan.connect(ssid, password)
while not wlan.isconnected():
    utime.sleep(1)  # sleep for a second
print("Network connected")

response = urequests.get('http://pastebin.com/raw/4309d09')
# do whatever is needed with your response
Sign up to request clarification or add additional context in comments.

2 Comments

I imported utime and get this error, also it like worked after 4-5 attempt for a few moments but didnt get request and then got the error again 'Traceback (most recent call last): File "<stdin>", line 12, in <module> OSError: Wifi Internal Error'
Fixed!, turns out something with my wifi, fixed with this discussion. github.com/orgs/micropython/discussions/10524 . Now it works. thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.