Page 1 of 1

OSError: scan failed

Posted: Sun Dec 18, 2016 3:00 am
by jamesb
wifi.scan() gives:

Code: Select all

>>> interface.scan()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: scan failed
I think it's when it can't see any wifi networks. I guess I'll enclose it in a try-except block, unless someone know a smart way around this?

Re: OSError: scan failed

Posted: Tue Oct 03, 2017 7:59 pm
by eradicatore
Hi,
Were you able to confirm this happens if the scan results in no networks found? I was hitting OS error on scans in one location last night very repeatedly, so I would assume you're right. But I just expected the documentation to also mention this pretty interesting way of reporting nothing found (rather than just an empty tuple).

Re: OSError: scan failed

Posted: Thu Nov 16, 2017 8:21 pm
by eradicatore
I still can't get the try/except to work around this failure when there are no wifi scan results. Does anyone else see this failure if there are zero ap's visible when you try to scan? Why would code like this not work?

Code: Select all

    try:
        scan_results = wifi.scan()
    except:
        ## for some odd reason OSERROR here means no wifi APs found
        scan_results = None
  

Re: OSError: scan failed

Posted: Fri Nov 17, 2017 11:17 am
by pythoncoder
Hmm. That's a hard one to test unless you live in Greenland ;) My Faraday cage (AKA microwave oven) is too small for my laptop. Ideas anyone?

Re: OSError: scan failed

Posted: Thu Jan 10, 2019 7:55 pm
by stundenblume
Hello,
eradicatore wrote:
Thu Nov 16, 2017 8:21 pm
I still can't get the try/except to work around this failure when there are no wifi scan results. Does anyone else see this failure if there are zero ap's visible when you try to scan? Why would code like this not work?
I know, this is very old but yes, I have the same Problem.

Re: OSError: scan failed

Posted: Thu Jan 10, 2019 8:31 pm
by Roberthh
For me it works. I made a little test script:

Code: Select all

from network import WLAN
wlan=WLAN()

while True:
    try:
        print(wlan.scan())
    except OSError:
        print("Silence")
Firmware: MicroPython v1.9.4-773-gafecc124-dirty on 2019-01-04; ESP module with ESP8266

I placed the ESP8266 in the microwave (thanks Peter), with the thinnest cable I could find, and got both scan results and 'Silence' printed. I must say that WiFi reception in our kitchen is poor, and the rssi, when received, was below -90 dB.

B.t.w.: Poor WiFi in the kitchen is not that bad for personal communication at the table.

Re: OSError: scan failed

Posted: Tue Jan 15, 2019 7:20 am
by stundenblume
Hello Robert,
thanks for testing. I will try it again, as I was testing I was in a train, right now I can't find a place without wifi signals.
Sebastian