Skip to content
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

QueryString encode issue with small fix #2077

Open
ebertti opened this issue Apr 8, 2020 · 1 comment
Open

QueryString encode issue with small fix #2077

ebertti opened this issue Apr 8, 2020 · 1 comment

Comments

@ebertti
Copy link

ebertti commented Apr 8, 2020

When the url has some querystring like:

http://domain.com/path/to/view/?query=some%40mail.com

django wait to receive this:

def some_view(request):
    query = request.GET.get('query')
    assert query == '[email protected]'

with Zappa 0.51.0 and Django 3.0.5 and python 3.7 on Lambda and ALB

this is the actual behavior

def some_view(request):
    query = request.GET.get('query')
    assert query == 'some%40mail.com'

So I made this small middleware to quick fix:

class FixQueryStringZappaMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        if os.envirion('FRAMEWORK') == 'Zappa':
            querystring = request.GET.urlencode()
            u = urllib.parse.unquote(querystring)
            request.GET = QueryDict(u)
        response = self.get_response(request)
        return response

and add this middleware as first of your list of middlewares

this is my zappa_settings.json

{
  "project": {
    "project_name": "project-backend",
    "aws_region": "sa-east-1",
    "alb_enabled": true,
    "apigateway_enabled": false,
    "cors": true,
    "keep_warm": false,
    "touch": false,
    "runtime": "python3.7",
    "timeout_seconds": 900,
    "log_level": "INFO",
    "s3_bucket": "some-bucket",
    "delete_s3_zip": false,
    "debug": true
  }
}
@choich
Copy link

choich commented Jul 6, 2020

I have same issue.
zappa does not encode the value of the url parameter.
http://url.com?a=abc,dfg -> http://url.com?a=abc%2Cdfg
Like this, the url encoded value is transmit as it is. In the example, %2C.
Normally %2C is transmit as,.

I am using zappa 0.50.0 version and python 3.6.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants