从micropy运行urequests.get时出现OSError -202 [英] getting OSError -202 where running urequests.get from micropy

查看:129
本文介绍了从micropy运行urequests.get时出现OSError -202的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有错误,但是它在python shell中运行,有什么机构可以帮助我

hi im having error with this code but it runs in python shell could any body help me

from machine import Pin
import time
import network
import urequests
p0 = Pin(0,Pin.OUT)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('ssid', 'pass')
response = urequests.get('http://jsonplaceholder.typicode.com/albums/1')
while True:
    ans = response.json()['userId']
    p0.value(1)
    time.sleep(1)
    p0.off()
    time.sleep(1)
    print('ok')

这是错误:

Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
  File "urequests.py", line 108, in get
  File "urequests.py", line 53, in request
OSError: -202

推荐答案

您的问题(我的猜测)是您开始使用urequest.get()而不连接WiFi.创建执行wifi连接的功能并调用它

Your issue (my guess) is that you begin to urequest.get() without connected to WiFi. Create function that do wifi connection and call it

def do_connect():
    import network
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect('essid', 'password')
        while not wlan.isconnected():
            pass
    print('network config:', wlan.ifconfig())

这篇关于从micropy运行urequests.get时出现OSError -202的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆