0

I am using azure cli in an alpine based docker container. I have installed azure-cli using pip2 on alpine.

When using azure-cli, in "vm create" command, I am getting above error.

az login #worked fine but 

az vm create -n ${VM_NAME} -g ${AZURE_RESOURCE_GROUP} --image ${VHD_URL} --os-type linux -- 
use-unmanaged-disk -l "Central US" --authentication-type password --admin-username ${USER} -- 
admin-password "${PASSWORD}" --storage-account ${AZURE_STORAGE_ACCOUNT} --storage- 
container-name ${AZURE_CONTAINER} --size Standard_DS3

53 Traceback (most recent call last):
54   File "/usr/lib/python2.7/logging/__init__.py", line 868, in emit
55     msg = self.format(record)
56   File "/usr/lib/python2.7/logging/__init__.py", line 741, in format
57     return fmt.format(record)
58   File "/usr/lib/python2.7/logging/__init__.py", line 469, in format
59     s = self._fmt % record.__dict__
60   File "/usr/lib/python2.7/site-packages/msrestazure/azure_exceptions.py", line 193, in 
__str__
61     return str(self.error)
62   File "/usr/lib/python2.7/site-packages/msrestazure/azure_exceptions.py", line 104, in 
__str__
63     error_str += "\n\tMessage: {}".format(error_obj.message)
64 UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 598: 
ordinal not in range(128)
65 Logged from file util.py, line 47
66 Traceback (most recent call last):
67   File "/usr/lib/python2.7/logging/__init__.py", line 868, in emit
68     msg = self.format(record)
69   File "/usr/lib/python2.7/site-packages/knack/log.py", line 78, in format
70     msg = logging.StreamHandler.format(self, record)
71   File "/usr/lib/python2.7/logging/__init__.py", line 741, in format
72     return fmt.format(record)
73   File "/usr/lib/python2.7/logging/__init__.py", line 469, in format
74     s = self._fmt % record.__dict__
75   File "/usr/lib/python2.7/site-packages/msrestazure/azure_exceptions.py", line 193, in 
__str__
76     return str(self.error)
77   File "/usr/lib/python2.7/site-packages/msrestazure/azure_exceptions.py", line 104, in 
__str__
78     error_str += "\n\tMessage: {}".format(error_obj.message)
79 UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 598: 
ordinal not in range(128)
80 Logged from file util.py, line 47

I know it's a python issue, I even tried installing azure cli with pip3 but that threw a different error "string doesn't have .message attribute"

Ashwani
  • 1,340
  • 1
  • 16
  • 34
  • We can tell you what character [U+2018](https://www.fileformat.info/info/unicode/char/2018/index.htm) is; would that help? – tripleee Feb 13 '20 at 19:39
  • Thank you, but I can not get anything out of this info as you can see I am just running azure cli command which is throwing error and the file in which error is happening is not handled by me. – Ashwani Feb 14 '20 at 05:14
  • Presumably one of the (incorrectly unquoted) strings you pass in might contain the problematic character? – tripleee Feb 14 '20 at 05:48
  • This command is working fine from last one year and nothing has changed environment-wise – Ashwani Feb 14 '20 at 05:50
  • 1
    Then my suspicion is that the geniuses at Microsoft have "improved" an internal error message to have curly quotes. Anyway, can you configure the locale of your container to enable Unicode output? Try setting `export PYTHONIOENCODING="utf-8"` and try again. If `echo "$LC_ALL"` displays something like `C` or `POSIX`, try setting it to `LC_ALL="en_US.utf-8"`. If this is a very minimal container, you may have to separately enable this locale with `localegen` or similar before this will work; but this box is already getting too small to cover all bases. – tripleee Feb 14 '20 at 06:08
  • Maybe see also https://stackoverflow.com/questions/11741574/how-to-print-utf-8-encoded-text-to-the-console-in-python-3 – tripleee Feb 14 '20 at 06:10
  • First thing I did was adding these lines: ENV LANG en_US.utf8 RUN export LC_ALL="en_US.UTF-8" && LC_CTYPE="en_US.UTF-8" && LANGUAGE="en_US.UTF-8" – Ashwani Feb 14 '20 at 09:33
  • If you are in a Dockerfile, use `ENV` for all of these. The `LANGUAGE` variable follow [a different convention](https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable) than the one you're trying to use. – tripleee Feb 14 '20 at 09:41
  • Okay, Let me try. – Ashwani Feb 14 '20 at 09:42
  • Still getting the same issue. – Ashwani Feb 14 '20 at 10:39
  • Could you [edit] the question to show your locale settings and e.g. the result of `python -c 'print(u"\u1234")'`? I guess there is no way you can switch to Python 3 for this? – tripleee Feb 14 '20 at 11:09
  • Are you really running `az vm create` inside a Docker container ...? – tripleee Feb 14 '20 at 11:11
  • Yes, I am using az cli in a container on Gitlab, I tried python3 also but there is also an issue that error_obj doesn't have "message attribute" – Ashwani Feb 15 '20 at 20:34
  • https://github.com/Azure/azure-cli/issues/12315 – HansHarhoff May 19 '20 at 05:38

0 Answers0