gpt4 book ai didi

python-3.x - 如何解决GET参数中的API key 错误?

转载 作者:行者123 更新时间:2023-12-04 10:01:32 27 4
gpt4 key购买 nike

我在 Lecture 4 - CS50's Web Programming with Python and JavaScript 2018 中遇到错误
我想弄清楚,但我不知道如何
我的代码是:

import requests

base = input("First currency: ")
other = input("Second currency: ")

res = requests.get("http://data.fixer.io/api/latest",params={"access_key":a8fc1a37ad16c61174a1f0395381ae41, "base": base, "symbols": other})
if res.status_code != 200:
raise Exception("ERROR: API request unsuccessful.")

data = res.json()
print(data)

我收到错误:
First currency: USD
Second currency: INR
Traceback (most recent call last):
File "c:/Users/kunal/lecture4/currency1.py", line 6, in <module>
res = requests.get("http://data.fixer.io/api/latest",params={"access_key":a8fc1a37ad16c61174a1f0395381ae41, "base": base, "symbols": other})
NameError: name 'a8fc1a37ad16c61174a1f0395381ae41' is not defined

最佳答案

a8fc1a37ad16c61174a1f0395381ae41是一个 api 键,它应该被格式化为一个字符串:

res = requests.get("http://data.fixer.io/api/latest",params={"access_key":"a8fc1a37ad16c61174a1f0395381ae41", "base": base, "symbols": other})

关于python-3.x - 如何解决GET参数中的API key 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61802713/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com