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

sev3333
  • 3
  • 2
  • 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. – easleyfixed Jun 27 '23 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? – hcheung Jun 28 '23 at 01:58
  • My url is fake :), I think its obvious that i would know whether it works or not. – sev3333 Jun 28 '23 at 12:48

1 Answers1

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
Lixas
  • 6,938
  • 2
  • 25
  • 42
  • 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 "", line 12, in OSError: Wifi Internal Error' – sev3333 Jun 28 '23 at 10:04
  • Fixed!, turns out something with my wifi, fixed with this discussion. https://github.com/orgs/micropython/discussions/10524 . Now it works. thank you :) – sev3333 Jun 28 '23 at 10:08