Azure / azure_preview_modules

Azure preview modules for Ansible
https://galaxy.ansible.com/azure/azure_preview_modules
43 stars 49 forks source link

CI error: UnicodeEncodeError: 'ascii' codec can't encode character u'\\u2018' in position 596 #359

Open internetionals opened 4 years ago

internetionals commented 4 years ago

This issue I've seen multiple times in both master branch CI tests and while working on #358.

Examples:

Excerpt:

"/home/travis/virtualenv/python2.7.15/lib/python2.7/site-packages/msrestazure/azure_exceptions.py", line 89, in __str__
   error_str += "Message: {}".format(self._message)
UnicodeEncodeError: 'ascii' codec can't encode character u'\\u2018' in position 596: ordinal not in range(128)

When looking at this error in the msrestazure python module we see it originates inside the CloudErrorData class. So this leads to me assuming that the Azure API is returning a unicode quote in it's error message.

The problem is that this error message is being encoded as 'ascii'. This is probably due to the environment the tests is being run in (when no special locale or language variables have been set then python will fall back to ascii encoded output).

internetionals commented 4 years ago

I did an experiment in #358 to see if setting PYTHONIOENCODING=utf-8 would help, but that didn't appear to change anything.

I'm still a bit mystified why python is choosing ascii encoding in this case, since setting the above variable appears to fix all relevant encodings, but that is probably due to my limited python experience.

I think the actual fix is to be made in the Azure/msrestazure-for-python project. Probably something along the lines of changing:

 89         error_str += "\nMessage: {}".format(self._message)

To:

 89         error_str += "\nMessage: {}".format(self._message.encode('ascii', 'replace'))
Fred-sun commented 4 years ago

@internetionals Thank you very much for your interest in Ansible. This repo is no longer maintained in this repository and has been migrated to https://github.com/ansible-collections/azure Please re-submit this Issue in the above repository and closed this. Thank you very much!