Starlette: request.query_params & request.url missing query params

Created on 9 Dec 2019  路  8Comments  路  Source: encode/starlette

Hey,

I have a simple test app (starlette==0.13.0) running and I noticed that requests only contain the first query parameter. All subsequent query params are trimmed out of the request url & query params:

curl http://localhost:8000/v1/posts?foo=bar&show=yes&test=1

The resulting request object in my view shows this:

URL('http://localhost:8000/v1/posts?foo=bar')
QueryParams('foo=bar')

image
image

Most helpful comment

ohhh wow, son of a gun! that's it 馃槉 sigh, my bad! thanks for helping get to the bottom of it!

All 8 comments

Hi @erichonkanen,
please, share a route definition you've used.

There isn't enough in this issue description to replicate an issue.

>>> from starlette.datastructures import URL, QueryParams
>>> u = URL('http://localhost:8000/v1/posts?foo=bar&show=yes&test=1')
>>> q = QueryParams(u.query)
>>> print(q)
QueryParams('foo=bar&show=yes&test=1')

I'm happy to reopen this, but only if its reduced to an absolutely minimal reproducible example case.

@tomchristie @alex-oleshkevich definitely, I was able to replicate it with this simple app and curl command:

# app.py

from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Mount, Route


async def posts(request):
    qp = request.query_params

    print(str(qp))
    # > foo=bar

    return JSONResponse({k: v for (k, v) in qp.items()})


routes = [Mount('/v1', routes=[
    Route('/posts', posts),
])]


app = Starlette(
    routes=routes,
)
uvicorn --host 0.0.0.0 app:app

curl http://localhost:8000/v1/posts?foo=bar&test=1&yes=true



md5-f7292d62f808999e4966eb8ceb35e97f



{"foo":"bar"}

That doesn't replicate for me at all?...

Screen Shot 2019-12-09 at 17 07 46

Screen Shot 2019-12-09 at 17 07 52

that's weird! it's happening for me on two fresh installs... is there any underlying lib that could impact it?

@tomchristie ok I just created new app again with above # app.py and discovered that making the request in the browser indeed works, whereas making the request with curl does not work.

Is there a header that when not present is affecting this?

image

image

Found it 馃ぃ It's a scripting issue...

$ curl http://localhost:8000/v1/posts?foo=bar&test=1&yes=true
                                             ^ Ampersand is a special character.

This is actually being interperated as:

  • curl http://localhost:8000/v1/posts?foo=bar
  • test=1
  • yes=true

Try echo $test; echo $yes and you'll see what I mean.

ohhh wow, son of a gun! that's it 馃槉 sigh, my bad! thanks for helping get to the bottom of it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PeriGK picture PeriGK  路  5Comments

zhammer picture zhammer  路  5Comments

Serkan-devel picture Serkan-devel  路  5Comments

tomchristie picture tomchristie  路  3Comments

MarcDufresne picture MarcDufresne  路  6Comments