2

I'm trying to do a simple get request with Micropython on an ESP32. Unfortunately I keep getting OSError: -202.

That's what I have so far:

wlan.py

import network

wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(True)       # activate the interface
wlan.connect('Schmittli', 'the key') # connect to an AP
wlan.ifconfig()         # get the interface's IP/netmask/gw/DNS addresses

And this is the REPL output:

>>> import wlan
import wlan
I (19080) wifi:wifi driver task: 3ffd1058, prio:23, stack:3584, core=0
I (38466) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (38466) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (38506) wifi:wifi firmware version: 44aa95c
I (38506) wifi:config NVS flash: enabled
I (38506) wifi:config nano formating: disabled
I (38506) wifi:Init dynamic tx buffer num: 32
I (38506) wifi:Init data frame dynamic rx buffer num: 32
I (38516) wifi:Init management frame dynamic rx buffer num: 32
I (38516) wifi:Init management short buffer num: 32
I (38526) wifi:Init static rx buffer size: 1600
I (38526) wifi:Init static rx buffer num: 10
I (38536) wifi:Init dynamic rx buffer num: 32
W (38536) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (38676) phy: phy_version: 4180, cb3948e, Sep 12 2019, 16:39:13, 0, 2
I (38696) wifi:mode : sta (30:ae:a4:f6:0f:08)
I (38696) wifi: STA_START
>>> I (38816) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (39666) wifi:state: init -> auth (b0)
I (39676) wifi:state: auth -> assoc (0)
I (39686) wifi:state: assoc -> run (10)
I (39706) wifi:connected with Schmittli, aid = 28, channel 1, BW20, bssid = a0:b5:49:00:c6:cd
I (39706) wifi:security type: 3, phy: bgn, rssi: -53
I (39706) wifi:pm start, type: 1

I (39716) network: CONNECTED
I (39776) wifi:AP's beacon interval = 102400 us, DTIM period = 3
I (42456) event: sta ip: 192.168.1.118, mask: 255.255.255.0, gw: 192.168.1.1
I (42456) network: GOT_IP


>>> import urequests
import urequests
I (72686) modsocket: Initializing
>>> response = urequests.get('http://jsonplaceholder.typicode.com/albums/1')
response = urequests.get('http://jsonplaceholder.typicode.com/albums/1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "urequests.py", line 108, in get
  File "urequests.py", line 53, in request
OSError: -202

I tried with two different ESP32 boards, so I don't think this is not a hardware problem. And yes, the URL works fine in my browser.

Update

Requesting the same service with it's IP address works. So it's a DNS Problem. I have 10+ diffrent devices on the same WLAN. All are working fine. So I really think this is a Mircopython problem.

This is the configuration, after the ESP32 connects to the WLAN:

>>> wlan.ifconfig()
wlan.ifconfig()
('192.168.1.116', '255.255.255.0', '192.168.1.1', '42.2.18.11')

In all my other devices the DNS server is '192.168.1.1'. I tried to set the DNS server manually in the ESP32, but that does not work:

>>> wlan.ifconfig('192.168.1.116', '255.255.255.0', '192.168.1.1', '192.168.1.1')
wlan.ifconfig('192.168.1.116', '255.255.255.0', '192.168.1.1', '192.168.1.1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function expected at most 2 arguments, got 5
>>> wlan.status()

Any ideas?

4
  • Did you try solution from with one stackoverflow.com/questions/64098376/… ? Commented Dec 18, 2020 at 13:46
  • I'm manually waiting for the connection, and the output states I (39716) network: CONNECTED, But I tried anyway. No change, I still get OSError: -202. Commented Dec 18, 2020 at 13:57
  • everything still seems to point to you WLAN configuration : your DHCP server hands out a different DNS server (42.2.18.11 = 42-2-18-011.static.netvigator.com) that is not allowing access to port 53 for DNS services. I would suggest you focus on getting the DHCP / network configuration resolved so that your MicroPython Board gets the proper dns server assigned. Commented Dec 21, 2020 at 10:57
  • 1
    the synx used in trying to set a static Ip & DNS is incorrect, you are missing (). ifconfig expects a tuple, not 4 parameters. (I agree the error could be clearer) wlan.ifconfig(('192.168.1.116', '255.255.255.0', '192.168.1.1', '192.168.1.1'))` should do better Commented Dec 21, 2020 at 11:09

2 Answers 2

3

It looks like you DNS server is not resolving the fqdn to an IP address for some reason.

  • run print(wlan.ifconfig()) to check your assigned DNS server in the last nibble
  • check if your DNS server perhaps is configured to filter queries from the specific client / subnet
  • resolve the FQDN to IP on a different client (your PC) , and use that IP address in MicroPython. If that works your DNS is the problem
  • you can also test your DNS using :
import socket
print(socket.getaddrinfo('micropython.org', 80))
print(socket.getaddrinfo('jsonplaceholder.typicode.com', 80))
# sample return
[(2, 1, 0, 'micropython.org', ('176.58.119.26', 80))]
[(2, 1, 0, 'jsonplaceholder.typicode.com', ('104.27.188.192', 80))]

If it is not your name resolution, you might be hitting a firewall.

Sign up to request clarification or add additional context in comments.

3 Comments

You are right. DNS ist not working. But why? I have iOS, OSX, RaperyPIs, Android and Windows devices on the same WLAN. They all work without problems.
is there any way to bypass the firewall problem? My service is running on the domain name which is resolved by our internal DNS server, I guess, cause using IP resolved by getAddrinfo on the browser does not work for obvious reason. I there any option to use microphython HTTP requests with the domain name and not IP?
in short: if you cannot resolve names to ip addresses , then you can't use names
0

add only two argument in wlan.ifconfig('192.168.4.1', '192.168.1.116')

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.