implicit encoding in Python
I have just finished debugging and fixing a curious issue related to the switch to Python 3. One of the cornerstones of this new version is the transparent implicit encoding of strings. You can read and write them and never care about explitic calls to
.encode and this is quite convenient. Well, I have learned to put them in proper places while I was using the previous version but I can't say I ever liked this, so I was happy to switch to Python 3.
However the migrated scripts didn't work reliably. The issue was made even more elusive by the immature tool I use to run them:
incron refuses to mail the output as decent crons do. I worked around that and looked in the logs and saw there
UnicodeEncodeError. WAT?! Everything worked perfectly when I ran it manually!
Then it hit me: environment variables. Shell had the language set, so Python could access it. But when the tool was running the script it didn't pass language, so Python had no idea which encoding to use. Luckily it's easy to set an environment variable.