KeyError ['date'] - Python fixer.io
KeyError ['date'] - Python fixer.io
我正在使用 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'
问题是,我不明白我怎么能 "declare" 这个约会对象,我的意思是,它显然缺少某种声明。
此外,关于 fixer.io
,您认为 requests
模块方法更好吗?
还是应该使用fixerio
python模块?
PS = 我正在使用 python 2.7
输出的快速打印显示 api 已损坏
import requests
import json
url = "http://api.fixer.io/latest?base=USD"
response = requests.get(url)
data = response.text
parsed = json.loads(data)
print(parsed)
{'0':
'#################################################################################################################################', '1': '#
如果您在浏览器中转到 url
,您会看到他们张贴了一条通知
{
"0": "#################################################################################################################################",
"1": "# #",
"2": "# IMPORTANT - PLEASE UPDATE YOUR API ENDPOINT #",
"3": "# #",
"4": "# This API endpoint is deprecated and has now been shut down. To keep using the Fixer API, please update your integration #",
"5": "# to use the new Fixer API endpoint, designed as a simple drop-in replacement. #",
"6": "# You will be required to create an account at https://fixer.io and obtain an API access key. #",
"7": "# #",
"8": "# For more information on how to upgrade please visit our Github Tutorial at: https://github.com/fixerAPI/fixer#readme #",
"9": "# #",
"a": "#################################################################################################################################"
}
所以密钥不存在。
我正在使用 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'
问题是,我不明白我怎么能 "declare" 这个约会对象,我的意思是,它显然缺少某种声明。
此外,关于 fixer.io
,您认为 requests
模块方法更好吗?
还是应该使用fixerio
python模块?
PS = 我正在使用 python 2.7
输出的快速打印显示 api 已损坏
import requests
import json
url = "http://api.fixer.io/latest?base=USD"
response = requests.get(url)
data = response.text
parsed = json.loads(data)
print(parsed)
{'0': '#################################################################################################################################', '1': '#
如果您在浏览器中转到 url
,您会看到他们张贴了一条通知
{
"0": "#################################################################################################################################",
"1": "# #",
"2": "# IMPORTANT - PLEASE UPDATE YOUR API ENDPOINT #",
"3": "# #",
"4": "# This API endpoint is deprecated and has now been shut down. To keep using the Fixer API, please update your integration #",
"5": "# to use the new Fixer API endpoint, designed as a simple drop-in replacement. #",
"6": "# You will be required to create an account at https://fixer.io and obtain an API access key. #",
"7": "# #",
"8": "# For more information on how to upgrade please visit our Github Tutorial at: https://github.com/fixerAPI/fixer#readme #",
"9": "# #",
"a": "#################################################################################################################################"
}
所以密钥不存在。