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

[Migrated] QueryString encode issue with small fix #836

Closed
jneves opened this issue Feb 20, 2021 · 2 comments
Closed

[Migrated] QueryString encode issue with small fix #836

jneves opened this issue Feb 20, 2021 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@jneves
Copy link
Contributor

jneves commented Feb 20, 2021

Originally from: Miserlou/Zappa#2077 by ebertti

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 == 'some@mail.com'

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
  }
}
@john-parton
Copy link

I think I'm experiencing a similar issue.

I think it might just be an ALB issue?

Wouldn't it be better to modify ZappaWSGIMiddleware to fix the encoding issue?

@monkut monkut added the duplicate This issue or pull request already exists label Jul 16, 2022
@monkut
Copy link
Collaborator

monkut commented Jul 16, 2022

considered a duplicate of
#879

closing

@monkut monkut closed this as completed Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants