0

My web app is deployed using nginx. I have view like below for the url /incoming/`.

def incoming_view(request):
    incoming = request.GET["incoming"]
    user = request.GET["user"]
    ...

When I hit my url /incoming/?incoming=hello&user=nkishore I am getting the response I need. but when I call this url using requests module with below code I am getting an error.

r = requests.get('http://localhost/incoming/?incoming=%s&user=%s'%("hello", "nkishore"))
print r.json()

I have checked the nginx logs and the request I got was /incoming/?incoming=hiu0026user=nkishore so in my view request.GET["user"] is failing to get user.

I am not getting what I am missing here, is it a problem with nginx or any other way to call in requests.

kishore
  • 413
  • 1
  • 4
  • 20
  • `user` is *not* a `User` object, it is just a vanilla `str`ing. – Willem Van Onsem Oct 15 '18 at 11:00
  • yeah it's just string I am trying to retrieve. If i hit the url `/incoming/?incoming=hello&user=nkishore` in my browser its working fine, problem with when I am calling using `requests` – kishore Oct 15 '18 at 11:04
  • What's this `hiu0026` in the log entry? And there's no `&` after `hiu0026` either. You should show us your actual code. – blhsing Oct 15 '18 at 11:05
  • But is the port number correct? Shouldn't this be `localhost:8000`? – Willem Van Onsem Oct 15 '18 at 11:05
  • What is the error? Also at the end of `nkishore` you have `'` instead of `"` – Josef Korbel Oct 15 '18 at 11:12
  • that's what I am not getting @blhsing, in the nginx log it's showing requested url like that `/incoming/?incoming=hiu0026user=nkishore` it's not converting `u0026` to `&` – kishore Oct 15 '18 at 11:12

1 Answers1

1

See Requests Docs for how to pass parameters, e.g.

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.get('https://httpbin.org/get', params=payload)
>>> print(r.url)
https://httpbin.org/get?key2=value2&key1=value1

Internally, Requests will likely escape the & ampersand with &. If you really want to do the URL manually, try as your URL string:

'http://localhost/incoming/?incoming=%s&user=%s'
C14L
  • 12,153
  • 4
  • 39
  • 52