AWS UnicodeDecodeError when creating application on ElasticBeanstalk - python

Trying to create a Python application on ElasticBeanstalk using the CLI, after I select my platform version I get the following error:
Select a platform version.
1) Python 3.4
2) Python
3) Python 2.7
4) Python 3.4 (Preconfigured - Docker)
(default is 1): 1
ERROR: UnicodeDecodeError :: 'ascii' codec can't decode byte 0xe2 in position 891: ordinal not in range(128)
I found this: https://github.com/aws/aws-cli/issues/708 which makes me think maybe I pasted my AWS credentials with a newline attached. I'd like to re-enter the credentials but it seems they are cached somewhere (it asked me for them on the first install attempt but not any subsequence attempts). I do not see them in my environment vars and I have been deleting .elasticbeanstalk between attempts. Any ideas?
update: I deleted .aws/config so it allowed me to re-enter my credentials. Still get the same error when I try to run eb init
update2: gist of --debug output can be found here: https://gist.github.com/dshuhler/8d64849021c48bf1ba71

tldr; My .gitignore had a hidden non-ascii character as I had copy pasted a Python specific .gitignore from a popular Github repository.
Steps I took to figure out the root cause
So, I couldn't find any answer that helped me solve this problem for me. Looks like, different people are seeing this error for different reasons.
I'm going to share the steps I took to figure out the cause for my problem. Make sure to run your command using --debug flag
$ eb init --debug
My output was something like this
2019-05-05 13:44:17,548 (INFO) eb : Traceback (most recent call last):
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/ebcli/core/ebrun.py", line 62, in run_app
app.run()
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/cement/core/foundation.py", line 797, in run
return_val = self.controller._dispatch()
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/cement/core/controller.py", line 472, in _dispatch
return func()
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/cement/core/controller.py", line 478, in _dispatch
return func()
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/ebcli/core/abstractcontroller.py", line 89, in default
self.do_command()
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/ebcli/controllers/initialize.py", line 118, in do_command
initializeops.setup(app_name, region_name, platform, dir_path=None, repository=repository, branch=branch)
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/ebcli/operations/initializeops.py", line 57, in setup
setup_ignore_file()
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/ebcli/operations/initializeops.py", line 92, in setup_ignore_file
source_control.set_up_ignore_file()
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/site-packages/ebcli/objects/sourcecontrol.py", line 294, in set_up_ignore_file
for line in f:
File "/Users/mudassirali/.virtualenvs/rtp_dev/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1287: ordinal not in range(128)
I jumped into the source code, specifically this bit
for line in f:
I found out this is the part which was throwing the error
with open('.gitignore', 'r') as f:
for line in f:
if line.strip() == git_ignore[0]:
return
Once I removed the .gitignore it worked like charm(and added it later without copy-paste)

It could be that your Beanstalk runs the Python environment without LC_ALL defined. Setting LC_ALL=en_US.UTF-8 in my Beanstalk environment properties resolved this issue for me.
Some background on these locale environment variables is available at: Explain the effects of export LANG, LC_CTYPE, LC_ALL

your aws credentials are at ~/.aws/config

Related

Anaconda prompt fail to launch: UnicodeEncodeError: 'utf-8' codec can't encode character '\udd8e': surrogates not allowed

I have Windows 10 x64 en-US and Anaconda3 2021.05. My anaconda prompt was working. Today it failed to launch and shows an error:
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\main.py", line 140, in main
return activator_main()
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\activate.py", line 1210, in main
print(activator.execute(), end='')
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\activate.py", line 178, in execute
return getattr(self, self.command)()
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\activate.py", line 153, in activate
return self._finalize(self._yield_commands(builder_result), self.tempfile_extension)
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\activate.py", line 143, in _finalize
tf.write(self.command_join.join(commands))
File "C:\ProgramData\Anaconda3\lib\tempfile.py", line 473, in func_wrapper
return func(*args, **kwargs)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udd8e' in position 952: surrogates not allowed
`$ C:\ProgramData\Anaconda3\Scripts\conda-script.py shell.cmd.exe activate C:\ProgramData\Anaconda3`
Anaconda PowerShell Prompt also fails to launch with similar error:
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\main.py", line 140, in main
return activator_main()
File "C:\ProgramData\Anaconda3\lib\site-packages\conda\activate.py", line 1210, in main
print(activator.execute(), end='')
UnicodeEncodeError: 'utf-8' codec can't encode character '\udd8e' in position 954: surrogates not allowed
`$ C:\ProgramData\Anaconda3\Scripts\conda-script.py shell.powershell activate C:\ProgramData\Anaconda3`
I searched around and tried everything, including:
Uninstall and reinstall Anaconda.
Upgrade Python to the latest version.
Add PYTHONIOENCODING=utf8 to environment variables.
Add "C:\ProgramData\Anaconda3" and "C:\ProgramData\Anaconda3\Scripts" to PATH.
Removing tempfile.py.
etc., couldn't fix it.
I searched this \udd8e character:
This is an unassigned character within a valid range, meaning it could be designated a valid Unicode code point in the future. However, for now it has no assigned value.
How could I fix this? Thank you very much.
The issue is a non-unicode letter in you PATH environment, which has to be deleted.
Go to your PATH environment file (control panel > system > advanced settings > environment variables) and delete paths under your local user account with non-unicode letters in it.
I had a similar error where setting the PYTHONIOENCODING=utf8 environment variable didn't work, but setting PYTHONUTF8=1fix it.

UnicodeDecodeError when trying to open Idle for Python 3.8

I tried launching idle on the command prompt by using python -i -m idlelib
This the error that occurred:
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 580, in <module>
main()
File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 567, in main
known_paths = addsitepackages(known_paths)
File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 350, in addsitepackages
addsitedir(sitedir, known_paths)
File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 208, in addsitedir
addpackage(sitedir, name, known_paths)
File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 164, in addpackage
for n, line in enumerate(f):
File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 654: character maps to undefined
Try python -i first and see if you can access the idle on the console.
Once you've verified that, you should then open idle on your pc and try import idlelib. If it doesn't load that means that either you don't have that module or its not in you path (which you can fix by finding its location and running import sys; sys.path.append("path/to/module")).
My guess would be that you have multiple versions of python on your pc and when you're running python you are not using the version that has this module.
A person here seems to have had a similar problem, albeit with a different program where the environmental variables they used caused problems. I recommend getting a package like conda. That'll reduce the likelihood of running into these problems immensely.

Can't save python script in IDLE with 2.7.11/12 [duplicate]

I ran APT-GET update on a Debian based OS on Oracle VB. While it was running I messed around with some python code in IDLE 2.7.12 (I opened it with a terminal). After it finished updating, I tried saving my code. In the terminal that I opened IDLE with I got an error. It says this:
root#kali:~# idle
Idle opens, I load my code, I edit my code, then I click [FILE] [SAVE]
This happens
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__
return self.func(*args)
File "/usr/lib/python2.7/idlelib/ScriptBinding.py", line 140, in run_module_event
filename = self.getfilename()
File "/usr/lib/python2.7/idlelib/ScriptBinding.py", line 205, in getfilename
self.editwin.io.save(None)
File "/usr/lib/python2.7/idlelib/IOBinding.py", line 345, in save
if self.writefile(self.filename):
File "/usr/lib/python2.7/idlelib/IOBinding.py", line 378, in writefile
chars = self.encode(self.text.get("1.0", "end-1c"))
File "/usr/lib/python2.7/idlelib/IOBinding.py", line 450, in encode
dialog = EncodingMessage(self.editwin.top, enc)
File "/usr/lib/python2.7/idlelib/IOBinding.py", line 76, in __init__
self.root = top = Toplevel(master)
NameError: global name 'Toplevel' is not defined
Picture of my terminal with the error
I have already tried restarting the VB, and I've uninstalled, autocleaned, then re-installed IDLE with no luck.
open IDLE.
Options
Configure IDLE
General
set 'Default Source Encoding' : UTF-8
I'm running Python 2.7.12 on Windows 10 and also Ubuntu 16.04 this solved my save/crash IDLE issue on both OS's .
Why do I get the feeling they are trying to throw us off Python 2 to 3 ?! jk.
The problem is a bug in the updated version of IDLE. Add the following near the top of .../Lib/idlelib/IOBinding.py, for instance before import tkFileDialog.
from Tkinter import *
The NameError occured in a function that displays a warning with the following message:
Non-ASCII found, yet no encoding declared. Add a line like
-*- coding: <enc> -*-
Choose OK to save this file as <enc>
Edit your general options to silence this warning
where <enc> will be an encoding such as utf-8.
It occurs to me that the message might be more helpful for beginners if it pointed to the Python Language Reference, Section 2.1.4., Encoding declarations
This bug is 2.x specific because in Python3, utf-8 is the default used in the absence of an encoding declaration.

Pip install raises UnicodeDecodeError on Windows. Fix?

When trying to install mysql-python on my Windows 10 machine i get the following error:
File "<string>", line 1, in <module>
File "C:\Users\LUCAFL~1\AppData\Local\Temp\pip-build-3u7aih0l\mysql-python\setup.py", line 21, in <module>
setuptools.setup(**metadata)
File "c:\program files (x86)\python35-32\lib\distutils\core.py", line 148, in setup
dist.run_commands()
...
File "c:\program files (x86)\python35-32\lib\subprocess.py", line 1055, in communicate
stdout = self.stdout.read()
File "c:\program files (x86)\python35-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1716: character maps to <undefined>
I tried installing other packages and received the same error on almost every one (one exception being pymysql). All of these packages were big and had dependencies. I guess that the big ones create temporary data in my user directories APPDATA folder. As you can see, the ü is not properly decoded (ü being byte 0x81). It's always a german umlaut that produces the error (mainly ü, as it's part of my user folders name).
I googled for the last 2 hours and found a lot of people having the same problem, but mostly they were opening github tickets or discussing the problem for Ubuntu/Fedora/OSX, etc. A couple times i read, that the standard encoding under windows is cp-1252 which causes the problem. Can i somehow force windows using my console to use utf-8 for this session and then run pip with that?
Please don't recommend me renaming my user folder. It's not easily done under Windows 10 and i dont want to re-install windows just because of python.
My setup: Windows 10, Python 3.5.1, pip 8.0.3
Can you try the following and see if it works. Replace path for python by your actual path.
I am not able to simulate on my windows laptop.
import sys
import subprocess
reload(sys) # Reload may do the trick!
sys.setdefaultencoding('UTF8')
theproc =subprocess.call(['C:\\Python27\\Scripts\\pip.exe', 'install', 'mysql-python'])
theproc.communicate()

Ropemacs does not work under windows environment

I am trying to use Emacs as my Python IDE under win32. I referred to several posts on the Internet and I had yasinppet, auto-complete, pymacs, ropemacs installed on my Emacs. It shows that Emacs will load python mode, rope mode, yas mode and auto-complete mode after I create a *.py file. But I got an error saying that the system cannot find pymacs.py file when I tried to use functions like "Goto definition" (C-c g) of rope. I am quite sure I have installed pymacs correctly and the path is right. So anyone can help me out of this?
WindowsError: [Error 3] The system cannot find the path specified:
Traceback (most recent call last):
File "C:\\Python27\\Pymacs\\Pymacs\\pymacs.py", line 265, in loop
value = eval(text)
File "<string>", line 1, in <module>
UnicodeDecodeError: \'ascii\' codec can\'t decode byte 0xe5 in position 12:
ordinal not in range(128)

Categories