-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary Support Not Working for Flask Application #1263
Comments
This may be a flask issue. By default I believe that flask attempts to return text/json as the response. If you want to respond to your request with binary data, you need to prevent flask from attempting to convert the response content to text. I believe send_file can be used to return a binary response. You can determine if this is a zappa issue by running flask locally and confirming that the error does not occur. |
Error does not occur locally, only when deployed to lambdas and api gateway. |
Can you provide the traceback with line numbers? |
I did this instead and this worked!! just needed to wrap the response object
|
Closing this as it appears to be resolved by adjusting the response in the flask app. |
Context
I am trying to serve byte responses from my zappa flask app. I enabled binary content types on my API gateway but i am still getting the error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
when i run zappa tail
Expected Behavior
I should be able to receive byte responses from my flask API Gateway
Actual Behavior
receiving UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte error
Possible Fix
(https://docs.aws.amazon.com/apigateway/latest/developerguide/lambda-proxy-binary-media.html)
Steps to Reproduce
@app.route('/')
def get_bytes_obj(path, format):
try:
return requests.get("https://www.google.com").content
except Exception as e:
print(e)
Your Environment
pip freeze
:Flask==2.2.2
boto3==1.26.43
requests==2.28.1
PyJWT==2.6.0
cryptography==39.0.1
zappa==0.57.0
zappa_settings.json
:{
"prod": {
"app_function": "app.app",
"aws_region": "us-east-1",
"profile_name": "default",
"project_name": "flask-image-ser",
"runtime": "python3.9",
"s3_bucket": "flask-image-server-v2",
"binary_support": true,
"payload_compression": true
}
}
The text was updated successfully, but these errors were encountered: