Search code examples
encodingutf-8aws-cli

Can I force AWS CLI (v1) to use UTF encoding?


Edit: Note this is an older question, from a time when AWS CLI was v1 - as noted in comments, there are other likely better solutions with v2

I'm using AWS CLI on Windows to query items from DynamoDb. Some of these items include non-ASCII characters.

When the query hits those items, it dies with an error

'charmap' codec can't encode character u'u010d' in position....

After hours of searching, I finally stumbled across a hackish workaround; under the AWSCLI\encodings directory, I copied utf_8.pyc over cp1252.pyc. This allows me to continue, but of course is ugly.

Before resorting to that, I also tried setting environment variables such as LANG, LC_ALL, LC_CTYPE to various permutations of en-US.UTF-8 or similar, all with no effect that I could see.

Does anyone know how (or is it even possible) to tell AWS CLI to use a particular encoding?


Solution

  • Since you're using the command line interface, a change to the terminal's encoding scheme should fix the issue.

    Type:

    chcp 65001
    

    in the console (for UTF-8; you may also try different encodings) and retry your operations.