Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

Zappa init: UnicodeDecodeError #1488

Open JoshZastrow opened 6 years ago

JoshZastrow commented 6 years ago

On Zappa init, possible issue with encoding using CP1252 with a flask application?

Context

On Zappa init, when defining the S3 bucket, Zappa errors out with a decode error:

AWS Lambda and API Gateway are only available in certain regions. Let's check to make sure you have a profile set up in one that will work.
Okay, using profile default!

Your Zappa deployments will need to be uploaded to a private S3 bucket.
If you don't have a bucket yet, we'll create one for you too.
What do you want call your bucket? (default 'zappa-5u4ed22rq'):

It looks like this is a Flask application.
Oh no! An error occurred! :(

==============

Traceback (most recent call last):
  File "c:\users\joshu\documents\code\machine-learning\boston-housing-price\app\env\venv\lib\site-packages\zappa\cli.py", line 2610, in handle
    sys.exit(cli.handle())
  File "c:\users\joshu\documents\code\machine-learning\boston-housing-price\app\env\venv\lib\site-packages\zappa\cli.py", line 476, in handle
    self.init()
  File "c:\users\joshu\documents\code\machine-learning\boston-housing-price\app\env\venv\lib\site-packages\zappa\cli.py", line 1604, in init
    matches = detect_flask_apps()
  File "c:\users\joshu\documents\code\machine-learning\boston-housing-price\app\env\venv\lib\site-packages\zappa\utilities.py", line 143, in detect_flask_apps
    lines = f.readlines()
  File "c:\users\joshu\documents\code\machine-learning\boston-housing-price\app\env\venv\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 301: character maps to <undefined>

Expected Behavior

Zappa init should run through the process and produce a dictionary of values / config.

Actual Behavior

A decode error generated

Possible Fix

Are adding coding statements to the top of an api.py file necessary?

Steps to Reproduce

  1. Install the newest version of Anaconda
  2. install virtualenv
  3. install zappa, flask, awscli
  4. create an S3 bucket
  5. write api.py code
  6. run zappa init

Your Environment

battini90 commented 6 years ago

I got the same error too. I am using the virtual environment on windows10, python3.6 and Zappa0.46.1 Also, in utilities.py, it was updated to io.open(full, 'r', encoding='utf-8') as f but I got same error. Traceback (most recent call last): File "d:\python-aws-diy\repo_stats\venv\lib\site-packages\zappa\cli.py", line 2693, in handle sys.exit(cli.handle()) File "d:\python-aws-diy\repo_stats\venv\lib\site-packages\zappa\cli.py", line 475, in handle self.init() File "d:\python-aws-diy\repo_stats\venv\lib\site-packages\zappa\cli.py", line 1546, in init \u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u255d \u255a\u2550\u255d \u255a\u2550\u255d\n""", fg='green', bold=True)) File "d:\python-aws-diy\repo_stats\venv\lib\site-packages\click\utils.py", line 259, in echo file.write(message) File "d:\python-aws-diy\repo_stats\venv\lib\site-packages\colorama\ansitowin32.py", line 40, in write self.__convertor.write(text) File "d:\python-aws-diy\repo_stats\venv\lib\site-packages\colorama\ansitowin32.py", line 141, in write self.write_and_convert(text) File "d:\python-aws-diy\repo_stats\venv\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert self.write_plain_text(text, cursor, len(text)) File "d:\python-aws-diy\repo_stats\venv\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text self.wrapped.write(text[start:end]) File "d:\python-aws-diy\repo_stats\venv\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-9: character maps to

Any help would be highly appreciated