AWS CLI upload failed: unknown encoding: idna

喜欢而已 提交于 2020-01-12 14:32:27

问题


I am trying to push some files up to s3 with the AWS CLI and I am running into an error:

upload failed: ... An HTTP Client raised and unhandled exception: unknown encoding: idna

I believe this is a Python specific problem but I am not sure how to enable this type of encoding for my python interpreter. I just freshly installed Python 3.6 and have verified that it being used by powershell and cmd.

$> python --version Python 3.6.7

If this isn't a Python specific problem, it might be helpful to know that I also just freshly installed the AWS CLI and have it properly configured. Let me know if there is anything else I am missing to help solve this problem. Thanks.


回答1:


I had the same problem in Windows.

After investigating the problem, I realized that the problem is in the aws-cli installed using the MSI installer (x64). After removing "AWS Command Line Interface" from the list of installed programs and installing aws-cli using pip, the problem was solved.

I also tried to install MSI installer x32 and the problem was missing.




回答2:


As a workaround, put the following import statement into the aws-script.py file.

import encodings.idna

Full path on 32-bit version is c:\Program Files (x86)\Amazon\AWSCLI\bin\aws-script.py

Full path on 64-bit version is C:\Program Files\Amazon\AWSCLI\bin\aws-script.py

I found this solution for a similar issue in this answer




回答3:


I've come across the same error and fixed by changing the order of AWC CLI and Python path:

Before:

PATH=C:\Program Files\Python35\Scripts\;C:\Program Files\Python35\;...;C:\Program Files\Amazon\AWSCLI\bin\;...

After:

PATH=...;C:\Program Files\Amazon\AWSCLI\bin\;...;C:\Program Files\Python35\Scripts\;C:\Program Files\Python35\

Looks like Python3 influences AWS CLI, which is just a cmd calling Python program.




回答4:


On Windows, this is probably an issue with the AWS-cli tools being installed using the MSI installer. It seems the best way to fix this issue is to use the aws-cli tools installed with python.

Prerequisites: Python3 and Pip3

Verify you have Python and Pip installed

C:\> python --version
Python 3.7.1
C:\> pip3 --version
pip 18.1 from c:\program files\python37\lib\site-packages\pip (python 3.7)

Uninstall the AWS-CLI tools MSI installer

Install the aws-cli tools with pip

C:\> pip3 install awscli

Check if aws-cli is in your path already ; if not, add it

C:\> where aws
C:\Program Files\Python37\Scripts\aws

If not, locate where the aws-cli tools are deployed and add the path to your PATH environment variable (can be set in Control panel > System > Advance system settings > Environment Variables...).

Below, common path of the deployed AWS cli tools:

Python 3 and pip3 – C:\Program Files\Python37\Scripts\

Python 3 and pip3 --user option on earlier versions of Windows – %USERPROFILE%\AppData\Local\Programs\Python\Python37\Scripts

Python 3 and pip3 --user option on Windows 10 – %USERPROFILE%\AppData\Roaming\Python\Python37\Scripts




回答5:


Even I was facing same issue. I was running it on Windows server 2008 R2. I was trying to upload around 500 files to s3 using below command.

aws s3 cp sourcedir s3bucket --recursive --acl bucket-owner-full-control --profile profilename

It works well and uploads almost all files, but for initial 2 or 3 files, it used to fail with error: An HTTP Client raised and unhandled exception: unknown encoding: idna

This error was not consistent. The file for which upload failed, it might succeed if I try to run it again. It was quite weird.

Tried on trial and error basis and it started working well.

Solution:

  1. Uninstalled Python 3 and AWS CLI.
  2. Installed Python 2.7.15
  3. Added python installed path in environment variable PATH. Also added pythoninstalledpath\scripts to PATH variable.
  4. AWS CLI doesnt work well with MS Installer on Windows Server 2008, instead used PIP.

Command:

pip install awscli

Note: for pip to work, do not forget to add pythoninstalledpath\scripts to PATH variable.

You should have following version:

Command:

aws --version

Output: aws-cli/1.16.72 Python/2.7.15 Windows/2008ServerR2 botocore/1.12.62

Voila! The error is gone!



来源:https://stackoverflow.com/questions/53144254/aws-cli-upload-failed-unknown-encoding-idna

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!