gpt4 book ai didi

python - 如何在 python 中将 quandl Api key 添加到我的请求中

转载 作者:太空狗 更新时间:2023-10-30 01:12:02 25 4
gpt4 key购买 nike

我已经创建了一个私有(private) quandl 帐户并收到了我的 quandl Api key ,但是如何在 python 中将 key 添加到我的请求中?

我的代码:

import pandas as pd 
import quandl

df = quandl.get('EOD/V')
print(df.head())

错误:

Traceback (most recent call last):
File "C:\Users\qasim\Documents\python_machine_learning\regression.py", line 4, in <module>
df = quandl.get('EOD/V')
File "C:\Python27\lib\site-packages\quandl\get.py", line 48, in get
data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
File "C:\Python27\lib\site-packages\quandl\model\dataset.py", line 47, in data
return Data.all(**updated_options)
File "C:\Python27\lib\site-packages\quandl\operations\list.py", line 14, in all
r = Connection.request('get', path, **options)
File "C:\Python27\lib\site-packages\quandl\connection.py", line 36, in request
return cls.execute_request(http_verb, abs_url, **options)
File "C:\Python27\lib\site-packages\quandl\connection.py", line 44, in execute_request
cls.handle_api_error(response)
File "C:\Python27\lib\site-packages\quandl\connection.py", line 85, in handle_api_error
raise klass(message, resp.status_code, resp.text, resp.headers, code)
quandl.errors.quandl_error.ForbiddenError: (Status 403) (Quandl Error QEPx05) You have attempted to view a premium database in anonymous mode, i.e., without providing a Quandl key. Please register for a free Quandl account, and then include your API key with your requests.
[Finished in 6.0s]

最佳答案

Configuration doc part 中,您可以使用 ApiConfig.api_key 进行设置:

import quandl
quandl.ApiConfig.api_key = 'tEsTkEy123456789'

此外,从 quandl python doc 中,您可以在 get 方法中定义额外的可选参数:

:param str api_key: Downloads are limited to 50 unless api_key is specified

所以你也可以使用:

df = quandl.get('EOD/V', api_key='tEsTkEy123456789')

关于python - 如何在 python 中将 quandl Api key 添加到我的请求中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45270315/

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