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)
Answer from Martijn Pieters on Stack Overflow
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
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_requests_post.asp
Python Requests post Method
The post() method is used when you want to send some data to the server. requests.post(url, data={key: value}, json={key: value}, args) args means zero or more of the named arguments in the parameter table below.
Discussions

httprequest - Python 'Requests' 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
Python request (post)
Is using requests post method the correct way to fill in a search box on a website? I have been reading the docs and they all seem to suggest using the requests get method adding the search query to the url. The problem I have is the website uses a search box which I need to put text in (I think). More on discuss.python.org
๐ŸŒ discuss.python.org
0
0
July 23, 2025
How to avoid URL encoding done by requests library while generating API key through XML version of Panorama API. Is there an alternate way of generating API without using the requests library?
In python I use urllib.parse.quote.. It works perfectly Use the request library to make the call More on reddit.com
๐ŸŒ r/paloaltonetworks
3
1
January 18, 2023
How to pass both file (uploaded) and dict params to POST request in FAST API?
How are you posting the data? What exactly are you sending? More on reddit.com
๐ŸŒ r/learnpython
2
1
April 15, 2022
People also ask

Does the Python requests library support asynchronous POST requests?

Unfortunately, the requests library does not support asynchronous requests. However, the httpx library is an alternative that provides async capabilities, making it suitable for applications requiring concurrency.

๐ŸŒ
scrapfly.io
scrapfly.io โ€บ blog โ€บ posts โ€บ how-to-python-requests-post
Guide to Python requests POST method
What is the difference between data and json parameters in Python requests?

data is for form-encoded (default) or raw data (when Content-Type header is overriden). While json is specifically for JSON format data and automatically sets Content-Type to application/json.

๐ŸŒ
scrapfly.io
scrapfly.io โ€บ blog โ€บ posts โ€บ how-to-python-requests-post
Guide to Python requests POST method
How can I include custom headers in using Python requests?

Pass headers as a dictionary using the headers parameter. Note that requests automatically generates some headers like User-Agent, Content-Length and Content-Type, so be cautious when overriding them.

๐ŸŒ
scrapfly.io
scrapfly.io โ€บ blog โ€บ posts โ€บ how-to-python-requests-post
Guide to Python requests POST method
๐ŸŒ
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....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ get-post-requests-using-python
GET and POST Requests Using Python - GeeksforGeeks
July 17, 2025 - And in most cases, the data provided is in JSON(JavaScript Object Notation) format (which is implemented as dictionary objects in Python!). ... # importing the requests library import requests # api-endpoint URL = "http://maps.googleapis.com/maps/api/geocode/json" # location given here location = "delhi technological university" # defining a params dict for the parameters to be sent to the API PARAMS = {'address':location} # sending get request and saving the response as response object r = requests.get(url = URL, params = PARAMS) # extracting data in json format data = r.json() # extracting l
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
๐ŸŒ
Scrapfly
scrapfly.io โ€บ blog โ€บ posts โ€บ how-to-python-requests-post
Guide to Python requests POST method
July 17, 2025 - Master Python requests POST method for sending JSON data, form submissions, and file uploads with proper error handling and authentication techniques. Use requests.post() with JSON parameter for API communication and data transmission
Find elsewhere
๐ŸŒ
ProxiesAPI
proxiesapi.com โ€บ articles โ€บ working-with-query-parameters-in-python-requests
Working with Query Parameters in Python Requests | ProxiesAPI
July 23, 2025 - Yes, query params can be used with any HTTP verb like GET, POST, PUT, etc. What are some common use cases for query parameters? Pagination, filtering, options, non-sensitive metadata.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Python request (post) - Python Help - Discussions on Python.org
July 23, 2025 - Is using requests post method the correct way to fill in a search box on a website? I have been reading the docs and they all seem to suggest using the requests get method adding the search query to the url. The probleโ€ฆ
๐ŸŒ
Requests
requests.readthedocs.io โ€บ en โ€บ latest โ€บ _modules โ€บ requests โ€บ api
requests.api โ€” Requests 2.32.5 documentation
[docs] def post(url, data=None, json=None, **kwargs): r"""Sends a POST request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-requests-post-request-with-headers-and-body
Python requests - POST request with headers and body - GeeksforGeeks
November 28, 2022 - data parameter takes a dictionary, a list of tuples, bytes, or a file-like object. Youโ€™ll want to adapt the data you send in the body of your request to the specified URL. ... requests.post(url, data={key: value}, json={key: value}, headers={key:value}, args) *(data, json, headers parameters are optional.)
๐ŸŒ
Real Python
realpython.com โ€บ python-requests
Python's Requests Library (Guide) โ€“ Real Python
September 26, 2025 - To send POST data, use the data parameter for form-encoded data or the json parameter for JSON data. response.text gives you a string representation of the response content, while response.content provides raw bytes.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ python โ€บ ighnykth โ€บ python-requests-post-example
How do I send a POST request using Python Requests Library?
March 22, 2019 - To send a POST request using the Python Requests Library, you should call the requests.post() method and pass the target URL as the first parameter and the POST data with the data= parameter.
๐ŸŒ
AnyIP
anyip.io โ€บ blog โ€บ python-requests-post
How to make a POST with the Python Requests module?
October 2, 2024 - Here are all the parameters you can use with the post(โ€ฆ) method: The return value of all HTTP requests made with the Requests package is a Response object.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ requests module โ€บ .post()
Python | Requests Module | .post() | Codecademy
May 15, 2024 - The .post() method sends a POST request to a web server and it returns a response object. ... Learn to analyze and visualize data using Python and statistics. ... Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today. ... **kwargs are any number of dictionary items (named arguments) that are passed in as parameters...
๐ŸŒ
Apidog
apidog.com โ€บ blog โ€บ python-post-request
How to send POST Request in python?
July 19, 2025 - In this example, data is a dictionary containing the data to be sent to the server. If youโ€™re sending JSON data, you can use the json parameter instead, which automatically sets the Content-Type header to application/json. Additionally, the requests.post function can accept several other keyword arguments (**kwargs) such as:
๐ŸŒ
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
February 21, 2009 - 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 ...
๐ŸŒ
Medium
medium.com โ€บ edureka โ€บ python-requests-tutorial-30edabfa6a1c
Python Requests Tutorial โ€” GET and POST Requests in Python | by Aayushi Johari | Edureka | Medium
July 12, 2025 - In this tutorial, you will learn how to use this library to send simple HTTP requests in Python. Requests allow you to send HTTP/1.1 requests. You can add headers, form data, multi-part files, and parameters with simple Python dictionaries, and access the response data in the same way.
๐ŸŒ
ProxiesAPI
proxiesapi.com โ€บ articles โ€บ sending-parameters-in-urls-with-the-python-requests-library
Sending Parameters in URLs with the Python Requests Library | ProxiesAPI
import requests url = 'https://api.example.com/products' params = { 'category': 'electronics', 'page': 2 } response = requests.get(url, params=params) ... params dictionary gets formatted into URL parameters, handling things like escaping special ...
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python requests โ€บ python requests: post request explained
Python requests: POST Request Explained โ€ข datagy
December 30, 2022 - Letโ€™s create our first POST request ... back, which returns a Response object. We can pass data into the request by using the data= parameter....
๐ŸŒ
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
June 26, 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 ...