I don't understand what I am supposed to do once I get this error message: InvalidHeader: Invalid return character or leading space in header: x-api-token
The code that generates this is the following:
import pandas as pd
!pip install pandas_datareader
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader as web
!pip install quandl
import quandl
quandl.ApiConfig.api_key=" my key"
oil = quandl.get("EIA/PET_RWTC_D")
This is the script for the oil price but I obtain the same result also for other securities. Thank you in advance.
Problem is with line quandl.ApiConfig.api_key=" my key" you are not allowed to insert space in api_key. the reason is internally quandl calls requests package of requests api and creates session, but unfortunately, off course it prepares the session and checks the header string. which doesn't allow space in between characters of api key.
Source code from package which talk about the same:-
def check_header_validity(header):
"""Verifies that header value is a string which doesn't contain
leading whitespace or return characters. This prevents unintended
header injection.
:param header: tuple, in the format (name, value).
"""