MicroPyramid / forex-python

Foreign exchange rates, Bitcoin price index and currency conversion using ratesapi.io
http://forex-python.readthedocs.io/en/latest/usage.html
MIT License
661 stars 195 forks source link

Getting error on getting the rates-> c.get_rates('USD') #118

Closed khurramshafiq07 closed 2 years ago

khurramshafiq07 commented 2 years ago

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
File ~\PythonEnv\EDT_OCR\lib\site-packages\requests\models.py:910, in Response.json(self, **kwargs)
    909 try:
--> 910     return complexjson.loads(self.text, **kwargs)
    911 except JSONDecodeError as e:
    912     # Catch JSON-related errors and raise as requests.JSONDecodeError
    913     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File ~\PythonEnv\EDT_OCR\lib\site-packages\simplejson\__init__.py:525, in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, **kw)
    521 if (cls is None and encoding is None and object_hook is None and
    522         parse_int is None and parse_float is None and
    523         parse_constant is None and object_pairs_hook is None
    524         and not use_decimal and not kw):
--> 525     return _default_decoder.decode(s)
    526 if cls is None:

File ~\PythonEnv\EDT_OCR\lib\site-packages\simplejson\decoder.py:370, in JSONDecoder.decode(self, s, _w, _PY3)
    369     s = str(s, self.encoding)
--> 370 obj, end = self.raw_decode(s)
    371 end = _w(s, end).end()

File ~\PythonEnv\EDT_OCR\lib\site-packages\simplejson\decoder.py:400, in JSONDecoder.raw_decode(self, s, idx, _w, _PY3)
    399         idx += 3
--> 400 return self.scan_once(s, idx=_w(s, idx).end())

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

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
Input In [191], in <cell line: 1>()
----> 1 c.get_rates('CAD')

File ~\PythonEnv\EDT_OCR\lib\site-packages\forex_python\converter.py:60, in CurrencyRates.get_rates(self, base_cur, date_obj)
     58 response = requests.get(source_url, params=payload)
     59 if response.status_code == 200:
---> 60     rates = self._decode_rates(response, date_str=date_str)
     61     return rates
     62 raise RatesNotAvailableError("Currency Rates Source Not Ready")

File ~\PythonEnv\EDT_OCR\lib\site-packages\forex_python\converter.py:40, in Common._decode_rates(self, response, use_decimal, date_str)
     38     decoded_data = json.loads(response.text, use_decimal=True)
     39 else:
---> 40     decoded_data = response.json()
     41 # if (date_str and date_str != 'latest' and date_str != decoded_data.get('date')):
     42 #     raise RatesNotAvailableError("Currency Rates Source Not Ready")
     43 return decoded_data.get('rates', {})

File ~\PythonEnv\EDT_OCR\lib\site-packages\requests\models.py:917, in Response.json(self, **kwargs)
    915     raise RequestsJSONDecodeError(e.message)
    916 else:
--> 917     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: [Errno Expecting value] a: 0
Rodrigosu1999 commented 2 years ago

Same problem, i try to run "c.get_rates('USD')" and it throws the following error

JSONDecodeError requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Traceback (most recent call last) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/requests/models.py", line 971, in json return complexjson.loads(self.text, kwargs) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/simplejson/init.py", line 525, in loads return _default_decoder.decode(s) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode obj, end = self.raw_decode(s) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) During handling of the above exception, another exception occurred: File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/flask-2/app.py", line 31, in check_if_valid_and_convert rates_from = c.get_rates(from_currency).keys() File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/forex_python/converter.py", line 60, in get_rates rates = self._decode_rates(response, date_str=date_str) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/forex_python/converter.py", line 40, in _decode_rates decoded_data = response.json() File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/requests/models.py", line 975, in json raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) During handling of the above exception, another exception occurred: File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/requests/models.py", line 971, in json return complexjson.loads(self.text, kwargs) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/simplejson/init.py", line 525, in loads return _default_decoder.decode(s) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode obj, end = self.raw_decode(s) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) During handling of the above exception, another exception occurred: File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/flask/app.py", line 2091, in call return self.wsgi_app(environ, start_response) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/flask/app.py", line 2076, in wsgi_app response = self.handle_exception(e) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/flask/app.py", line 2073, in wsgi_app response = self.full_dispatch_request() File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/flask/app.py", line 1519, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/flask/app.py", line 1517, in full_dispatch_request rv = self.dispatch_request() File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/flask/app.py", line 1503, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/flask-2/app.py", line 36, in check_if_valid_and_convert f"CONVERT FROM: Invalid currency type. Please type with correct format (e.g. 'USD') {from_currency} {c_symbol.get_symbol(from_currency)} {c.get_rates(from_currency).keys()} ") File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/forex_python/converter.py", line 60, in get_rates rates = self._decode_rates(response, date_str=date_str) File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/forex_python/converter.py", line 40, in _decode_rates decoded_data = response.json() File "/home/rodrigo/Springboard/20_Assesment_3_Forex_Converter/venv/lib/python3.8/site-packages/requests/models.py", line 975, in json raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

mpeterson-sf commented 2 years ago

Yes, I am getting the same error I would appreciate any help on this issue.

ashwin31 commented 2 years ago

fixed

dokiak commented 1 year ago

how?