invoke: ascii encoding failure under Python 3 on EC2 / Elastic Beanstalk

See description in this comment on #350 by @aleksihakli: https://github.com/pyinvoke/invoke/issues/350#issuecomment-232641766


Quick note: hide=True just skips the automatic mirroring to stdout/err; presumably if one manually were to try printing or decoding run(...).stdout it’d explode there too.


I’m wondering why this is breaking for @aleksihakli; is their environment a normal-ish EC2 instance with a human user at a terminal? Or is Elastic Beanstalk executing it in a more limited environment?

They’re on Python 3.4, so Invoke isn’t manually encoding the string, it’s assuming Python 3’s io writer classes are doing the correct thing. My best guess is that in this case something is triggering use of a writer class that does not do the correct thing; or that the outer environment has properties we haven’t encountered yet.

Hoping Aleksi can shed some light here 😃

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

I think I found the solution setting the environment variable LANG to UTF-8 entry make it works. So in my case adding the line below to my Dockerfile solve the UnicodeError that was thrown by npm. ENV LANG=en_US.UTF-8

I see the same issue with Invoke 0.13.0 on Python 3.5 running on CentOS 7 when running mocha tests for our Node builds.

Calling run('mocha specs') fails with UnicodeEncodeError: 'ascii' codec can't encode characters in position 58: ordinal not in range(128).

You’re right that calling run with hide=True does not fail, but subsequently printing result.stdout will fail with the same error.