我正在尝试使用以下指令导入Quandl数据:
quandl.get('WIKI/GOOGL')
弹出以下错误:
Traceback (most recent call last):
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 55, in parse
return response.json()
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/requests/models.py", line 850, in json
return complexjson.loads(self.text, **kwargs)
File "/home/shravilp/anaconda3/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/home/shravilp/anaconda3/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/shravilp/anaconda3/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last):
File "ml1.py", line 4, in <module>
df = quandl.get('WIKI/GOOGL')
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/get.py", line 48, in get
data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/model/dataset.py", line 47, in data
return Data.all(**updated_options)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/operations/list.py", line 14, in all
r = Connection.request('get', path, **options)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 36, in request
return cls.execute_request(http_verb, abs_url, **options)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 44, in execute_request
cls.handle_api_error(response)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 61, in handle_api_error
error_body = cls.parse(resp)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 57, in parse
raise QuandlError(http_status=response.status_code, http_body=response.text)
quandl.errors.quandl_error.QuandlError: (Status 403) Something went wrong. Please try again. If you continue to have problems, please contact us.
以下是我的代码:
import pandas as pd
import quandl
df = quandl.get("FRED/GDP")
print(df.head())
最佳答案
如Quandl API文档所述,错误403指出您需要API密钥才能访问该密钥。以下是纠正它的步骤-
1.在Quandl上创建一个免费/高级帐户。
2.从帐户设置选项生成API密钥。
3.在脚本中将您的API密钥包括为quandl.ApiConfig.api_key =“ YOURAPIKEY”。
关于python - Quandl不起作用,弹出一些错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44516353/