3

When using requests-mock, my querystring data is lowercased:

request.post('http://foo.bar', params={'Foo': 'Bar'})

def foo_bar(self, request, context):
    import pdb; pdb.set_trace()

The actual value of request.qs will be {'foo': ['bar']}.

How do I get it to not lower case my query string data?

There's a bug that should be fixed in 1.1: https://bugs.launchpad.net/requests-mock/+bug/1584008

I'm using 1.3 though and still having this issue.

Michael_Scharf
  • 33,154
  • 22
  • 74
  • 95
dan-klasson
  • 13,734
  • 14
  • 63
  • 101
  • 1
    Are you sure? Try: `requests.post('http://httpbin.org/post', data={'Foo': 'Bar'}).json()`. `Foo` and `Bar` **are not lowercased**. Where are you reading your `qs` from? – randomir Aug 27 '18 at 04:54
  • 2
    Also, if you [search `requests`](https://github.com/requests/requests/search?p=1&q=lower&unscoped_q=lower) code, the only place `lower()` is used in a destructive manner is for headers, not for form parameters. – randomir Aug 27 '18 at 05:01
  • @randomir Sorry, that should be `params` and not `data`. Using `params`, I assume, will send the POST as querystring, and thus it shows up in `resp.qs`. Using `data` sends it as raw data and it shows up in `resp.text`. In both scenarios `resp.json()` will be empty. – dan-klasson Aug 27 '18 at 05:13
  • 1
    @dan-klasson can you edit your question to make a reproducible example, for example using `'http://httpbin.org/post'` as in @randomir's comment? – maxymoo Aug 27 '18 at 05:18
  • @dan-klasson, you are still not telling us everything :) Because `requests.post('http://httpbin.org/post', params={'Foo': 'Bar'}).json()` still shows proper query string is sent (case preserved). – randomir Aug 27 '18 at 05:24
  • 1
    @randomir Yes you're right. `qs` seems to come from requests mock library. – dan-klasson Aug 27 '18 at 05:28
  • Should be fixed in 1.3 which is what I'm using though: https://bugs.launchpad.net/requests-mock/+bug/1584008 – dan-klasson Aug 27 '18 at 05:31
  • That's why it's useful to include a MVC example - not only to help answerers, but also for sanity check. :) – randomir Aug 27 '18 at 05:35
  • @randomir Yeah, down with the flu, not thinking straight. Still doesn't solve my problem though. – dan-klasson Aug 27 '18 at 05:40
  • 1
    So I would recommend you close this question, and open a new one, in which you'll include the exact and complete problem you're trying to solve. I.e. a minimal code segment that reproduces the problem (or bug). Because right now, this question is unanswerable. – randomir Aug 27 '18 at 05:44

0 Answers0