There is a json that is such a format that is parsed in the program:

 [ "ООО Один", "ООО Два", "ООО \"Три\" (3379)" ] 

When you run the program in docker and try to generate the file, the following error occurs:

  File "app/handlers/delegate/basic_delegate_handler.py", line 25, in __init__ self.special_list = json.loads(f.read()) File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 5: ordinal not in range(128) 

Without docker on the main machine, everything works. Another interesting fact is that the error says about ascii , although the file is stored in utf-8 .

The original image is using ubuntu:16.04 .

  • what image do you use? - Mikhail Vaysman
  • @MikhailVaysman added to his question - faoxis
  • What is needed is not the original image, but the image in which you run. - Mikhail Vaysman
  • Perhaps the fact is that by default for some reason the system has the encoding 'ANSI_X3.4-1968' . How to change to UTF-8 ? The image of faoxis/ubuntu_flask . - faoxis
  • the storage encoding does not affect the interpretation coding in any way, there can be any encoding comments in the text of the document, but simply the text file does not declare its encoding in any way - etki

2 answers 2

Add to your Dockerfile

 RUN locale-gen en_US.UTF-8 RUN update-locale LANG=en_US.UTF-8 LC_MESSAGES=POSIX 

This will set the default locale.

    If you are reading json from a file, then explicitly specify the encoding (it is extremely likely that utf-8):

     #!/usr/bin/env python3 import json with open("special_list.json", encoding="utf-8") as file: special_list = json.load(file) 

    Your code worked outside of docker, since open() uses the locale.getpreferredencoding(False) default encoding and you have a utf-8 locale configured.

    In docker, you probably have no locale configured, which is equivalent to a C / POSIX locale that uses ascii encoding.

    You should not change the locale just to read the file in a different encoding (although it may be useful to install the utf-8 locale for other reasons).