-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bizarre issue with JSON request bodies getting mutated #110
Comments
Thanks for reporting! Especially for the repro. Investigating.. |
I have a committed a fix to master that I THINK will fix this, but needs code review and more testing. 8f47569 |
(You will need to 'undeploy' and 'redeploy' for the changes to take affect, I think.) |
The type will still be a string, but I think that's actually the correct behavior - it's the job of the application do the the parsing properly, Zappa's job is just the scurry the data. |
Right, I don't quite understand the fix, but I think it is it. I was seeing different behavior when specifying Content-Type and when not, but at some point when writing the reproducible example I lost the point where the result differed (things get confused when you're getting errors). I'll test the new code later today. Thank you. |
It has kind of fixed it, but there's a different issue now: fiatjaf@cantillon ~/c/webhooks> curl -X POST https://fj9czanxrk.execute-api.us-east-1.amazonaws.com/test/test -d '{"x":22}'
{"x":22}⏎
fiatjaf@cantillon ~/c/webhooks> curl -X POST https://fj9czanxrk.execute-api.us-east-1.amazonaws.com/test/test -d '{"x":22}' -H 'Content-Type: application/json'
<!DOCTYPE html>500.
From Zappa: <pre>must be string or buffer, not dict</pre><br />
<pre>Traceback (most recent call last):<br />
File "/var/task/handler.py", line 122, in handler<br />
trailing_slash=False<br />
File "/home/fiatjaf/comp/webhooks/venv/lib/python2.7/site-packages/zappa/wsgi.py", line 25, in create_wsgi_request<br />
File "/usr/lib64/python2.7/base64.py", line 73, in b64decode<br />
return binascii.a2b_base64(s)<br />
TypeError: must be string or buffer, not dict<br /></pre>⏎ |
Good catch, I see the issue, needs thought. More soon. |
Pushed another fix, although I fear I may have gone too far in the other direction.. |
Now it is working for me, although I don't quite understand all the changes involved, thank you very much. Am I expecting what is the correct expected behavior, or will this change in the future? |
The correct behavior should be to get the same inputs/outputs across Zappa as you would in any traditional deployment, so yes. Leaving this ticket open until this is tested and published. |
Published. |
I don't know if this is an issue with Lambda or Zappa, but since I couldn't find anyone complaining from this strange bug that would affect anyone using JSON to send data to Lambda functions, I guess it is more likely that the problem is here? (Maybe it is a Flask bug also, but I couldn't find anything there also and it doesn't make sense that Flask works differently locally and in the Lambda environment -- or maybe does?)
Here's my Flask app (full code):
Here's what happens when I test it locally:
Then I deploy (everything looks normal for me):
Testing the "live" version (here's where the problem appears):
Why is my
{"x": 22}
JSON getting mutated to{x=22}
? This is odd, very odd. These logs don't show it, but I have also tried to logtype(data)
and it is<str>
({key=value}
is not the standard way Python prints objects anyway).The lambda logs show the following:
I'm using Python 2.7.10, a virtualenv and running zappa from inside the virtualenv, so I think I'm doing everything right as explained in the books. I just don't know what is that Exception that appears on the beggining of Lambda logs right there. Could it be the cause? I doubt it, but who knows?
The text was updated successfully, but these errors were encountered: