【发布时间】:2019-02-22 01:45:07
【问题描述】:
所以,这很奇怪。我正在尝试让一个脚本在我的 RaspberryPi 上运行,以从 weatherunderground 的 JSON 流中获取天气数据。我在最新的 Raspbian-Stretch OS 上使用 Python3.5 开发新的 Raspberry Pi。它在其他机器上运行时工作(通过 VisualStudio 的 Windows 和另一个运行相同发行版的 Raspberry Pi 和 LEDES 发行版上的 Onion Omega2)
我正在阅读的行(根据本网站的其他搜索编辑)是:
import urllib.request
import json
# Get and load the weather data from my house weather station.
weatherdata = urllib.request.urlretrieve("http://api.wunderground.com/api/<myAPIKey-hidden here>/conditions/q/pws:KKYLOUIS68.json")
weatherinfo = json.loads(weatherdata.read())
shell 的返回是这样的:
Traceback (most recent call last):
File "/home/pi/myweather_win.py", line 18, in <module>
weatherinfo = json.loads(weatherdata.read())
AttributeError: 'tuple' object has no attribute 'read'
我不是程序员,只是想学习,这让我很困惑,因为它正在其他系统上工作。
【问题讨论】:
标签: python json python-3.x tuples urllib