我从 fixerio 重新开始,我有这个代码:
import requests
import json
url = "http://api.fixer.io/latest?base=USD"
response = requests.get(url)
data = response.text
parsed = json.loads(data)
date = parsed["date"]
print("Date:", date, "\n")
rates = parsed["rates"]
for currency, rate in rates.items():
print(currency, "= USD", rate)
每次我运行它时,它都会抛出:
C:\usio>python fixerio.py
Traceback (most recent call last):
File "fixerio.py", line 9, in <module>
date = parsed["date"]
KeyError: 'date'
问题是,我不明白如何“声明”这个日期,我的意思是,它显然缺少某种声明。
另外,谈到fixer.io
,您认为requests
模块方法更好吗?
还是应该使用fixerio
python 模块?
PS =我正在使用python 2.7