Flask test_client removes query string parameters


Question

I am using Flask to create a couple of very simple services. From outside testing (using HTTPie) parameters through querystring are getting to the service.

But if I am using something like.

    data = {
        'param1': 'somevalue1',
        'param2': 'somevalue2'}

    response = self.client.get(url_for("api.my-service", **data))

I can see the correct URI being created:

http://localhost:5000/api1.0/my-service?param1=somevalue1&param2=somevalue2

when I breakpoint into the service:

request.args

is actually empty.

self.client is created by calling app.test_client() on my configured Flask application.

Anyone has any idea why anything after ? is being thrown away or how to work around it while still using test_client?

1
11
12/12/2015 1:58:09 PM

I've just found out a workaround.

Make

data = {
    'param1': 'somevalue1',
    'param2': 'somevalue2'}

response = self.client.get(url_for("api.my-service", **data))

into this:

data = {
    'param1': 'somevalue1',
    'param2': 'somevalue2'}

response = self.client.get(url_for("api.my-service"), query_string = data)

This works but seems a bit unintuitive, and debugging there is a place where the provided query string in the URI is thrown away ....

But anyway this works for the moment.

21
1/20/2015 10:37:00 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon