quandl / quandl-python

MIT License
1.37k stars 336 forks source link

Http 403 error with correct api key #125

Closed giraygokirmak closed 5 years ago

giraygokirmak commented 5 years ago

data = quandl.get("FRED/GDP") print(data.head()) With correct api key (already renewed api key and checked with curl the same request as https://www.quandl.com/api/v3/datasets/FRED/GDP/data.json?api_key=XXXXXXXXXX and it returns correct formatted json) but Quandl 3.4.3 does return:


JSONDecodeError Traceback (most recent call last) /usr/local/lib/python3.5/dist-packages/quandl/connection.py in parse(cls, response) 54 try: ---> 55 return response.json() 56 except ValueError:

/usr/local/lib/python3.5/dist-packages/requests/models.py in json(self, kwargs) 895 pass --> 896 return complexjson.loads(self.text, kwargs) 897

/usr/lib/python3.5/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 318 parse_constant is None and object_pairs_hook is None and not kw): --> 319 return _default_decoder.decode(s) 320 if cls is None:

/usr/lib/python3.5/json/decoder.py in decode(self, s, _w) 338 """ --> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 340 end = _w(s, end).end()

/usr/lib/python3.5/json/decoder.py in raw_decode(self, s, idx) 356 except StopIteration as err: --> 357 raise JSONDecodeError("Expecting value", s, err.value) from None 358 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

QuandlError Traceback (most recent call last)

in ----> 1 data = quandl.get("FRED/GDP") 2 print(data.head()) /usr/local/lib/python3.5/dist-packages/quandl/get.py in get(dataset, **kwargs) 46 if dataset_args['column_index'] is not None: 47 kwargs.update({'column_index': dataset_args['column_index']}) ---> 48 data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True) 49 # Array 50 elif isinstance(dataset, list): /usr/local/lib/python3.5/dist-packages/quandl/model/dataset.py in data(self, **options) 45 updated_options = Util.merge_options('params', params, **options) 46 try: ---> 47 return Data.all(**updated_options) 48 except NotFoundError: 49 if handle_not_found_error: /usr/local/lib/python3.5/dist-packages/quandl/operations/list.py in all(cls, **options) 12 options['params'] = {} 13 path = Util.constructed_path(cls.list_path(), options['params']) ---> 14 r = Connection.request('get', path, **options) 15 response_data = r.json() 16 Util.convert_to_dates(response_data) /usr/local/lib/python3.5/dist-packages/quandl/connection.py in request(cls, http_verb, url, **options) 34 abs_url = '%s/%s' % (ApiConfig.api_base, url) 35 ---> 36 return cls.execute_request(http_verb, abs_url, **options) 37 38 @classmethod /usr/local/lib/python3.5/dist-packages/quandl/connection.py in execute_request(cls, http_verb, url, **options) 42 response = func(url, **options) 43 if response.status_code < 200 or response.status_code >= 300: ---> 44 cls.handle_api_error(response) 45 else: 46 return response /usr/local/lib/python3.5/dist-packages/quandl/connection.py in handle_api_error(cls, resp) 59 @classmethod 60 def handle_api_error(cls, resp): ---> 61 error_body = cls.parse(resp) 62 63 # if our app does not form a proper quandl_error response /usr/local/lib/python3.5/dist-packages/quandl/connection.py in parse(cls, response) 55 return response.json() 56 except ValueError: ---> 57 raise QuandlError(http_status=response.status_code, http_body=response.text) 58 59 @classmethod QuandlError: (Status 403) Something went wrong. Please try again. If you continue to have problems, please contact us at connect@quandl.com.
jjmar commented 5 years ago

Hello,

Could you update to 3.4.4 and see if this issue still occurs? Additionally, which specific version of python 3.5 are you using?

giraygokirmak commented 5 years ago

I'm having the same problem on 3.4.4 with Python 3.5.2 and 3.6.7 versions with the code example below: import quandl quandl.ApiConfig.api_key = '***' data = quandl.get("FRED/GDP")

jjmar commented 5 years ago

I've attempted to make that same call using both Python 3.5.2 and Python 3.6.7 in addition to making the request using the api_key associated with the Quandl account linked to the email visible on your github profile page and I get successful responses.

giraygokirmak commented 5 years ago

I finally figured out the problem, it seems like my server's ip is banned by cloudflare somehow (probably all subnet is banned because of some stupid abuser) I debugged the request and saw that i'm acutally receiving this: "Attention Required! | Cloudflare\n" So i'm closing the issue, i'm so sory that i took your time buddy.