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

Attempt to read /raw_data/currencies.json as ascii instead of utf-8 breaks get_symbol() #109

Open cgeorgelee opened 2 years ago

cgeorgelee commented 2 years ago

Under certain conditions, python tries to read /raw_data/currencies.json as ascii instead of utf-8 and it cannot read the file. See the stacktrace below.

Traceback (most recent call last):
  File "/corp/views/current/project/business/display.py", line 160, in get_currency_symbol
    currency_symbol = cc.get_symbol("USD")
  File "/corp/virtualenvs/corpweb/lib/python3.8/site-packages/forex_python/converter.py", line 140, in get_symbol
    currency_dict = self._get_data(currency_code)
  File "/corp/virtualenvs/corpweb/lib/python3.8/site-packages/forex_python/converter.py", line 132, in _get_data
    currency_dict = next((item for item in self._currency_data if item["cc"] == currency_code), None)
  File "/corp/virtualenvs/corpweb/lib/python3.8/site-packages/forex_python/converter.py", line 128, in _currency_data
    self.__currency_data = json.loads(f.read())
  File "/usr/lib64/python3.8/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7400: ordinal not in range(128)
2022-05-26 00:35:53,423 ERROR display(165): get_currency_symbol: Could not decode currency_code: USD
cgeorgelee commented 2 years ago

This is under called by Django, python 3.8, under virtualenvs on AWS Linux 2