0

I'm struggling to understand the difference between my workstation environment and the gitlab-ci docker environment. Yes, it is one of those UnicodeDecodeError: ... ordinal not in range(128) exception that we know and love.

My problem is that it works on my workstation and not in the docker instance of gitlab-ci. I have created a project to demonstrate the problem. The pipeline output is here: https://gitlab.com/moozer/unicode-test/-/jobs/205999852

The code that I run is:

import sys
import platform

print( "Load and show file - testing unicode and such")
print( "python version: {}".format(platform.python_version()))

print( "Showing content from file {}".format( sys.argv[1]))
print( "---")
with open( sys.argv[1], "r" ) as fp:
    content = fp.read()
    print( "read content is of type {}".format( type(content )))
    print( content )
print("--- EOF")

So there are some difference between the environment on my workstation and in the docker container that shows when using python3 and using non-ascii chars.

How to debug?

Suggestions are welcome :-)

moozer
  • 75
  • 1
  • 7
  • Have you checked this thread https://stackoverflow.com/questions/21129020/how-to-fix-unicodedecodeerror-ascii-codec-cant-decode-byte ? – Umair Mohammad May 02 '19 at 11:52
  • Check the locale settings in the container. – snakecharmerb May 02 '19 at 12:09
  • 1
    @UmairMohammad good link. He has some good examples. In one the replies, he mentions issues related to output and that "print" checks the locale. On my workstation defaultlocale is ("en_US", "UTF-8"), while in gitlab it is (None, None) Thanks for the pointers – moozer May 02 '19 at 12:45
  • @snakecharmerb Thanks. Yes I found some comments hinting in that directions, so I'm doing that now. – moozer May 02 '19 at 12:49
  • 1
    I have solved it now - both for python2 and python3. It was bad locale settings in the container - I expect that to be common, since it will rarely be the focus for the container-designer. The solution was to add `export PYTHONIOENCODING=utf8` before running the python scripts. The project with some sample code and a .gitlab-ci.yml is here: https://gitlab.com/moozer/unicode-test/tree/StackOverflow-ok Thanks for the help. – moozer May 02 '19 at 13:09

0 Answers0