Skip to content

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

Open
@cgeorgelee

Description

@cgeorgelee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions