params is for GET-style URL parameters, and data is for POST-style body information. It is perfectly legal to provide both types of information in a request, and your request does so too, but you encoded the URL parameters into the URL already.

Your raw post contains JSON data though. Requests can handle JSON encoding for you, and it'll set the correct Content-Type header too; all you need to do is pass in the Python object to be encoded as JSON into the json keyword argument.

You could split out the URL parameters as well:

params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

Then post your data with:

import requests

url = 'http://192.168.3.45:8080/api/v2/event/log'

data = {"eventType": "AAS_PORTAL_START", "data": {"uid": "hfe3hf45huf33545", "aid": "1", "vid": "1"}}
params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

requests.post(url, params=params, json=data)

The json keyword is new in Requests version 2.4.2; if you still have to use an older version, encode the JSON manually using the json module and post the encoded result as the data key; you will have to explicitly set the Content-Type header in that case:

import requests
import json

headers = {'content-type': 'application/json'}
url = 'http://192.168.3.45:8080/api/v2/event/log'

data = {"eventType": "AAS_PORTAL_START", "data": {"uid": "hfe3hf45huf33545", "aid": "1", "vid": "1"}}
params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

requests.post(url, params=params, data=json.dumps(data), headers=headers)
Answer from Martijn Pieters on Stack Overflow
🌐
Requests
requests.readthedocs.io › en › latest › user › quickstart
Quickstart — Requests 2.33.0.dev1 documentation
You often want to send some sort ... in the URL after a question mark, e.g. httpbin.org/get?key=val. Requests allows you to provide these arguments as a dictionary of strings, using the params keyword argument....
Top answer
1 of 3
453

params is for GET-style URL parameters, and data is for POST-style body information. It is perfectly legal to provide both types of information in a request, and your request does so too, but you encoded the URL parameters into the URL already.

Your raw post contains JSON data though. Requests can handle JSON encoding for you, and it'll set the correct Content-Type header too; all you need to do is pass in the Python object to be encoded as JSON into the json keyword argument.

You could split out the URL parameters as well:

params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

Then post your data with:

import requests

url = 'http://192.168.3.45:8080/api/v2/event/log'

data = {"eventType": "AAS_PORTAL_START", "data": {"uid": "hfe3hf45huf33545", "aid": "1", "vid": "1"}}
params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

requests.post(url, params=params, json=data)

The json keyword is new in Requests version 2.4.2; if you still have to use an older version, encode the JSON manually using the json module and post the encoded result as the data key; you will have to explicitly set the Content-Type header in that case:

import requests
import json

headers = {'content-type': 'application/json'}
url = 'http://192.168.3.45:8080/api/v2/event/log'

data = {"eventType": "AAS_PORTAL_START", "data": {"uid": "hfe3hf45huf33545", "aid": "1", "vid": "1"}}
params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

requests.post(url, params=params, data=json.dumps(data), headers=headers)
2 of 3
18

Assign the response to a value and test the attributes of it. These should tell you something useful.

response = requests.post(url, params=data, headers=headers)
response.status_code
response.text
  • status_code should just reconfirm the code you were given before, of course
Discussions

Oddity in handling params in `requests.get`
We had been doing: query = {'product': product} resp = requests.get(url, params=query) but we noticed that when we changed it to be: url = f'{url}?{"&".join(f"{k}={urllib.parse.quote(v)}" for k, v in query.items())}' resp = requests.get(url) we were getting faster responses from the server. More on discuss.python.org
🌐 discuss.python.org
0
0
September 24, 2024
httprequest - Python Request Post with param data - Stack Overflow
It is perfectly legal to provide ... the URL parameters into the URL already. Your raw post contains JSON data though. requests can handle JSON encoding for you, and it'll set the correct Content-Type header too; all you need to do is pass in the Python object to be encoded ... More on stackoverflow.com
🌐 stackoverflow.com
oauth - Constructing requests with URL Query String in Python - Stack Overflow
@elykl33t Then use requests-oauthlib ... parameters, then construct a GET request with query string as mentioned in my answer. 2013-07-22T13:36:10.96Z+00:00 ... This is something I have thought about, but I was not sure how to do. How could I obtain the signature from the request? A big reason I am having issues with this is just because my Python experience ... More on stackoverflow.com
🌐 stackoverflow.com
How can I filter the result of the api call "Get projects paginated" using the QUERY PARAMETERS in python?
Hi, I’m trying to get the key information of the project using the project name for one automation that i’m working on in python. It is the first time i’m doing that, so i’m strugling with placing the query parameter “query” correctly. The definition of “query” parameter in ... More on community.developer.atlassian.com
🌐 community.developer.atlassian.com
0
0
February 19, 2021
🌐
W3Schools
w3schools.com › python › ref_requests_get.asp
Python Requests get Method
Python Examples Python Compiler ... Q&A Python Bootcamp Python Certificate Python Training ... The get() method sends a GET request to the specified url....
🌐
ProxiesAPI
proxiesapi.com › articles › working-with-query-parameters-in-python-requests
Working with Query Parameters in Python Requests | ProxiesAPI
Query parameters provide a way to pass data in a key-value format in your request URLs. Mastering their usage is key for productive web scraping and API integration in Python.
🌐
CodeSignal
codesignal.com › learn › courses › basic-python-and-web-requests › lessons › mastering-data-retrieval-query-parameters-and-rest-apis-in-python
Query Parameters and REST APIs in Python
For example, if you ever filtered a search result on a website and noticed your URL change to something like this http://website.com/search?param1=value1&param2=value2, those are query parameters in action! Python's requests library offers a simple way to pass those query parameters.
🌐
Python.org
discuss.python.org › python help
Oddity in handling params in `requests.get` - Python Help - Discussions on Python.org
September 24, 2024 - We had been doing: query = {'product': product} resp = requests.get(url, params=query) but we noticed that when we changed it to be: url = f'{url}?{"&".join(f"{k}={urllib.parse.quote(v)}" for k, v in query.items())}' resp = requests.get(url) we were getting faster responses from the server.
Find elsewhere
🌐
Medium
medium.com › @jazeem.lk › handling-parameters-in-get-requests-with-requests-module-37b125179ba5
Handling Parameters in GET Requests with requests module | by azeem jainulabdeen | Medium
November 22, 2024 - Query parameters are appended to the URL after a ? and are typically used to filter or customize the response. For example: ... import requests # Using query parameters url = 'https://httpbin.org/get' params = {'id': 1} # Query parameters are ...
🌐
APIPark
apipark.com › techblog › en › mastering-python-requests-sending-query-parameters
Mastering Python Requests: Sending Query Parameters
October 31, 2025 - If an API requires something like nested objects in query parameters (e.g., filter[user][name]=John), requests doesn't natively support converting a nested Python dictionary into this specific URL format automatically for GET requests.
🌐
Packetcoders
packetcoders.io › how-to-add-query-parameters-to-api-calls-with-requests-in-python
How to Add Query Parameters to API Calls with requests in Python
May 20, 2025 - Easily add query parameters to your API calls when using Python by using the params argument in requests.get(). Here`s an example 👇 import requests # Define API endpoint url = "http://suzieq-server/api/v2/devices" # Query parameters to filter ...
Top answer
1 of 3
453

params is for GET-style URL parameters, data is for POST-style body information. It is perfectly legal to provide both types of information in a request, and your request does so too, but you encoded the URL parameters into the URL already.

Your raw post contains JSON data though. requests can handle JSON encoding for you, and it'll set the correct Content-Type header too; all you need to do is pass in the Python object to be encoded as JSON into the json keyword argument.

You could split out the URL parameters as well:

params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

then post your data with:

import requests

url = 'http://192.168.3.45:8080/api/v2/event/log'

data = {"eventType": "AAS_PORTAL_START", "data": {"uid": "hfe3hf45huf33545", "aid": "1", "vid": "1"}}
params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

requests.post(url, params=params, json=data)

The json keyword is new in requests version 2.4.2; if you still have to use an older version, encode the JSON manually using the json module and post the encoded result as the data key; you will have to explicitly set the Content-Type header in that case:

import requests
import json

headers = {'content-type': 'application/json'}
url = 'http://192.168.3.45:8080/api/v2/event/log'

data = {"eventType": "AAS_PORTAL_START", "data": {"uid": "hfe3hf45huf33545", "aid": "1", "vid": "1"}}
params = {'sessionKey': '9ebbd0b25760557393a43064a92bae539d962103', 'format': 'xml', 'platformId': 1}

requests.post(url, params=params, data=json.dumps(data), headers=headers)
2 of 3
18

Assign the response to a value and test the attributes of it. These should tell you something useful.

response = requests.post(url,params=data,headers=headers)
response.status_code
response.text
  • status_code should just reconfirm the code you were given before, of course
🌐
Medium
m-t-a.medium.com › python-why-you-cant-use-arrays-in-query-strings-with-requests-and-urllib-and-how-to-fix-it-da0ad2ad2e06
Python: Why you can’t use Arrays in Query Strings with Requests and urllib | by Michael T. Andemeskel | Medium
February 21, 2021 - I remember working in PHP and how miserable I was but everything did what you expected it to do when it came to requests. This was a surprising gotcha for a language as mature and user-friendly as Python. People write code and people forget I guess. In the end, I decided to use a loop to populate the parameters: extra_fields = [ "PictureURLLarge", "PictureURLSuperSize", "GalleryInfo", "UnitPriceInfo"] query_params = { "RESPONSE-DATA-FORMAT": "JSON", "REST-PAYLOAD": "true", "paginationInput.entriesPerPage": 100, "paginationInput.pageNumber": page_number, } for index in range(0, len(extra_fields)): field = extra_fields[index] query_params[f"outputSelector[{index}]"] = fieldresponse = requests.get(REQUEST_URL, params = query_params)
🌐
Real Python
realpython.com › python-requests
Python's Requests Library (Guide) – Real Python
July 23, 2025 - One common way to customize a GET request is to pass values through query string parameters in the URL. To do this using get(), you pass data to params. For example, you can use GitHub’s repository search API to look for popular Python ...
🌐
FastAPI
fastapi.tiangolo.com › tutorial › query-params
Query Parameters - FastAPI
The query is the set of key-value pairs that go after the ? in a URL, separated by & characters. ... As they are part of the URL, they are "naturally" strings. But when you declare them with Python types (in the example above, as int), they are converted to that type and validated against it. All the same process that applied for path parameters ...
Top answer
1 of 2
76

To perform GET requests with URL query string:

import requests

params = {
    'action': 'subscribe',
    'callbackurl': '',
    'comment': '',
    'oauth_consumer_key': '',
    'oauth_nonce': '',
    # more key=value pairs as appeared in your query string
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)

With that cleared, now you just need to follow the workflow documented on http://www.withings.com/en/api/oauthguide and implement them

  1. Upon receiving your OAuth Key and OAuth Secret, perform a GET request with the following endpoint and query string which will give you back token:

    https://oauth.withings.com/account/request_token? oauth_callback=http%3A%2F%2Fexample.com%2Fget_access_token &oauth_consumer_key=c331c571585e7c518c78656f41582e96fc1c2b926cf77648223dd76424b52b &oauth_nonce=f71972b1fa93b8935ccaf34ee02d7657 &oauth_signature=J8xzgFtHTsSRw8Ejc8UDV2jls34%3D &oauth_signature_method=HMAC-SHA1 &oauth_timestamp=1311778988 &oauth_version=1.0

  2. Then you need to authorize the token you received with the following request which will give you the user_id:

    https://oauth.withings.com/account/authorize? oauth_callback=http%3A%2F%2Fexample.com%2Fget_access_token &oauth_consumer_key=c331c571585e7c518c78656f41582e96fc1c2b926cf77648223dd76424b52b &oauth_nonce=369f9ceb2f285ac637c9a7e9e98019bd &oauth_signature=OR9J9iEl%2F2yGOXP2wk5c2%2BWtYvU%3D &oauth_signature_method=HMAC-SHA1 &oauth_timestamp=1311778988 &oauth_token=5bb105d2292ff43ec9c0f633fee9033045ed4643e9871b80ce586dc1bf945 &oauth_version=1.0

  3. Then you need to request the access_token by hitting this endpoint with some more query string:

    https://oauth.withings.com/account/access_token? oauth_consumer_key=c331c571585e7c518c78656f41582e96fc1c2b926cf77648223dd76424b52b &oauth_nonce=7acd22371fc56fd8a0aaf8416f79f84f &oauth_signature=jmj1g%2FB3rYR2DCpWp86jB5YVHIM%3D &oauth_signature_method=HMAC-SHA1 &oauth_timestamp=1311778988 &oauth_token=5bb105d2292ff43ec9c0f633fee9033045ed4643e9871b80ce586dc1bf945 &oauth_version=1.0 &userid=831

  4. Now you have everything needed to perform the aforementioned request in your question, and others, example directly from the documentation:

    http://wbsapi.withings.com/measure? action=getmeas &oauth_consumer_key=c331c571585e7c518c78656f41582e96fc1c2b926cf77648223dd76424b52b &oauth_nonce=accbac1b7ee2b86b828e6dc4a5a539b2 &oauth_signature=XfobZMboIg2cRyNKAvyzONHHnKM%3D &oauth_signature_method=HMAC-SHA1 &oauth_timestamp=1311842514 &oauth_token=887557411788d5120537c6550fbf2df68921f8dd6f8c7e7f9b441941eb10 &oauth_version=1.0 &userid=831

Again, everything can be done without explicit oauth library as you can finish the workflow with requests.get and query string built from a dict feed into the params argument of the method.

I truly hope this helps you achieve your goal.

2 of 2
2

Here's a working example using the rauth client library. Full disclosure, I'm the original rauth author. Hope this helps:

from rauth import OAuth1Service

withings = OAuth1Service(
        name='withings',
        consumer_key='fd5fe4002db502983fbd056fdf416941d83e15ecb68ee9eeb4978cb2370c',
        consumer_secret='29dbc46056c530814c2debcf24c76ff42f6cc66d0e3e5cfdef1e166725c6f',
        base_url='http://wbsapi.withings.net/notify',
        request_token_url='https://oauth.withings.com/account/request_token',
        authorize_url='http://oauth.withings.com/account/authorize',
        access_token_url='https://oauth.withings.com/account/access_token')

request_token, request_token_secret = withings.get_request_token()

callback = 'https://github.com/litl/rauth'

authorize_url = withings.get_authorize_url(request_token,
                                           oauth_callback=callback)

print('Visit this URL in your browser: {url}'.format(url=authorize_url))
userid = raw_input('Enter userid from browser URL: ')

sess = withings.get_auth_session(request_token,
                                 request_token_secret,
                                 params={'userid': userid})

print sess.get('measure', params={'action': 'getmeas',
                                  'userid': userid}).json()
🌐
Atlassian Developer Community
community.developer.atlassian.com › jira development › jira cloud
How can I filter the result of the api call "Get projects paginated" using the QUERY PARAMETERS in python? - Jira Cloud - The Atlassian Developer Community
February 19, 2021 - It is the first time i’m doing that, so i’m strugling with placing the query parameter “query” correctly. The definition of “query” parameter in jira api is: Filter the results using a literal string.
Top answer
1 of 3
73

You cannot use requests for this; the library builds such URLs if passed a Python structure for the parameters, but does not offer any tools to parse them. That's not a goal of the project.

Stick to the urllib.parse method to parse out the parameters. Once you have a dictionary or list of key-value tuples, just pass that to requests to build the URL again:

try:
    # Python 3
    from urllib.parse import urlparse, parse_qs
except ImportError:
    # Python 2
    from urlparse import urlparse, parse_qs

o = urlparse(url)
query = parse_qs(o.query)
# extract the URL without query parameters
url = o._replace(query=None).geturl()

if 'token' in query:
    query['token'] = 'NEW_TOKEN'

requests.get(url, params=query)

You can get both the urlparse and parse_qs functions in both Python 2 and 3, all you need to do is adjust the import location if you get an exception.

Demo on Python 3 (without the import exception guard) to demonstrate the URL having been built:

>>> from urllib.parse import urlparse, parse_qs
>>> url = "http://httpbin.org/get?token=TOKEN_TO_REPLACE&param2=c"
>>> o = urlparse(url)
>>> query = parse_qs(o.query)
>>> url = o._replace(query=None).geturl()
>>> if 'token' in query:
...     query['token'] = 'NEW_TOKEN'
... 
>>> response = requests.get(url, params=query)
>>> print(response.text)
{
  "args": {
    "param2": "c", 
    "token": "NEW_TOKEN"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.5.1 CPython/3.4.2 Darwin/14.1.0"
  }, 
  "origin": "188.29.165.245", 
  "url": "http://httpbin.org/get?token=NEW_TOKEN&param2=c"
}
2 of 3
22

Using requests only:

query = requests.utils.urlparse(url).query
params = dict(x.split('=') for x in query.split('&'))

if 'token' in params:
    params['token'] = 'NEW_TOKEN'

requests.get(url, params=params)
🌐
datagy
datagy.io › home › python requests › python requests: get request explained
Python requests: GET Request Explained • datagy
December 30, 2022 - Query string parameters allow you to customize a GET request by passing values directly into the URL or into the params= parameter.
🌐
Reddit
reddit.com › r/learnpython › after learning about python requests, i have just a few questions i want to ask.
r/learnpython on Reddit: After learning about python requests, I have just a few questions I want to ask.
August 29, 2021 -

So, if I understand correctly, you can use get to get back a response of some basic HTML? And then you can add get parameters to change what you get in the response? (Like maybe a URL parameter could be saying you want filtering videos by new which would return different html than filtering by hot)?

And them I am kind of confused about post and put, because how do you know what you want post something to a website..

payload = {'username': 'Franklin', 'password': 'testing'}

r = requests.post('https://httpbin.org/post', data=payload)

In this example, if it was a real website, how would I know what the payload keys should be? Do I have to look through the HTML?

Same thing goes with the Put method.

TLDR: How do I know what paramaters/values/keys/whatevers I need to post or put to a website for a request?

Thanks for the help!

Top answer
1 of 5
32
So, if I understand correctly, you can use get to get back a response of some basic HTML? HTML is a markup language. The thing web servers do is respond to requests over a protocol called HTTP, the HyperText Transport Protocol. requests, the library, sends requests to those servers via HTTP. What you get back depends on what you send and what the web server is configured to do. So that gets to your real question, which is a very good question indeed: TLDR: How do I know what paramaters/values/keys/whatevers I need to post or put to a website for a request? Well, whoever wrote the web service API you're sending requests to has to tell you. Ideally they tell you via their API documentation site, and then you just go look up the different endpoints you can send requests to and the different parameters they require or accept. Kind of boring to read API docs, honestly, so I usually just read the parts that seem like they pertain to what I'm trying to do and work outwards from there. Sometimes they don't do that, or they don't want to do that, and you have to get a little clever. You muck around with their web site in a normal web browser and pay attention to what URL's get looked up and how they're parameterized, or you run the browser with its dev console open and snoop on the requests the web site makes to its server. You try to look for patterns and make educated guesses and then you experiment with making your own and seeing what you can get up to. If it sounds like that sucks and takes a long time and is at least a little bit hacky, you're right. It's a big pain in the ass to have to do this kind of snooping on a web service to figure out what its API is, so it has to be worth it.
2 of 5
14
I've found the tool: "Postman" to be very useful in both understanding how this works, and also in day to day use after that to work out values, visualize responses, etc. When you've got that html correct, you can get the python code with the push of a button. There should be lots of tutorials and YouTube videos on Postman.
🌐
Python For All
pythonforall.com › modules › requests › rsquery
Working with Query Parameters in Requests | PythonForAll
February 9, 2026 - To send query parameters, you can include them as a dictionary in the params argument of a requests.get() call. The library automatically encodes the parameters and appends them to the URL.
🌐
Reddit
reddit.com › r/learnpython › apis: params= vs json= whats the difference?
r/learnpython on Reddit: APIs: Params= vs json= whats the difference?
November 26, 2021 -

Been learning more about accessing APIs and stuff. I keep running into things about params and json to do requests. I don't exactly understand what the difference between these two is. I use the same dictionaries but the keyword differs.

I tried to read the documentation but its a bit more technical than my ability.