J. Woods J. Woods - 22 days ago 4
Python Question

Python Requests - add text at the beginning of query string

When sending data through python-requests a GET request, I have a need to specifically add something at the beginning of the query string. I have tried passing the data in through dicts and json strings with no luck.

The request as it appears when produced by requests:


The request as it appears when produced by their interactive API documentation (Swagger):


Where the key-value pairs of my data follow the excerpt above.

Ultimately, I think the missing piece is the record= that gets produced by their documentation. It is the only piece that is different from what is produced by Requests.

At the moment I've got it set up something like this:

import requests
s = requests.Session()
s.auth = requests.auth.HTTPBasicAuth(username,password)
s.verify = certificate_path

# with data below being a dictionary of the values I need to pass.
r = s.get(url,data=data)

I am trying to include an image of the documentation below, but don't yet have enough reputation to do so:

apply/model/explain documentation

wim wim

'GET' requests don't have data, that's for 'POST' and friends.

You can send the query string arguments using params kwarg instead:

>>> params = {'record': '{"'}
>>> response = requests.get('http://www.example.com/explain', params=params)
>>> response.request.url