MicroPython调用API时出现OSError: -6错误求助
问题:Raspberry Pi Pico W调用API持续触发OSError: -6
问题详情
原本可正常运行2-3次的API调用代码,未做任何修改的情况下,现在所有涉及API调用的程序都会抛出OSError: -6错误。尝试更换urequests以外的库(如usocket)、调用不同API均无法解决,目标网站在浏览器中可正常访问。更换运行Thonny的电脑、使用旧版本Thonny也无效,错误始终一致。
错误日志如下:
>>> %Run -c $EDITOR_CONTENT Traceback (most recent call last): File "<stdin>", line 8, in <module> File "urequests.py", line 180, in get File "urequests.py", line 76, in request OSError: -6 >>>
运行环境
- MicroPython版本:v1.19.1-1014-gbde222ce8(2023-04-11)
- 硬件:搭载RP2040的Raspberry Pi Pico W
- IDE:Thonny 4.0.2(运行于Windows 10系统)
测试代码
import urequests import json # URL for the sunrise/sunset API endpoint url = "https://api.sunrise-sunset.org/json?lat=37.7749&lng=-122.4194&formatted=0" # Make an HTTP GET request to the API endpoint response = urequests.get(url) # Parse the JSON response data = json.loads(response.text) # Extract the sunrise and sunset times from the JSON data sunrise = data["results"]["sunrise"] sunset = data["results"]["sunset"] # Print the sunrise and sunset times to the screen print("Sunrise: {}".format(sunrise)) print("Sunset: {}".format(sunset))
内容的提问来源于stack exchange,提问作者Davandjes
相关产品推荐
相关产品推荐

