UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 3 2: ordinal not in range(128)

后端 未结 6 1309
轻奢々
轻奢々 2020-11-30 22:50

I am parsing an xsl file using xlrd. Most of the things are working fine. I have a dictionary where keys are strings and values are lists of strings. All the keys and values

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 23:33

    I had exactly this issue in a recent project which really is a pain in the rear. I finally found it's because the Python we used in Docker has encoding "ansi_x3.4-1968" instead of "utf-8". So if anyone out there using Docker and got this error, following these steps may thoroughly solve your problem.

    1. create a file and name it default_locale in the same directory of your Dockerfile, put this line in it,

      environment=LANG="es_ES.utf8", LC_ALL="es_ES.UTF-8", LC_LANG="es_ES.UTF-8"

    2. add these to your Dockerfile,

      RUN apt-get clean && apt-get update && apt-get install -y locales

      RUN locale-gen en_CA.UTF-8

      COPY ./default_locale /etc/default/locale

      RUN chmod 0755 /etc/default/locale

      ENV LC_ALL=en_CA.UTF-8

      ENV LANG=en_CA.UTF-8

      ENV LANGUAGE=en_CA.UTF-8

    This thoroughly solved my issue when I built and run my Docker again, hopefully this solve your issue also.

提交回复
热议问题