How can I pass a dict a query param for a POST request in Python?

I am trying to make a POST request with a param which is a dict.

Is it possible or do I have to convert it to something else?

import requests

def do_random_request(self, random_dictionary: dict, random_number: int, random_name: str):
  url = "https://api.random-site.com/"
  params = {
    "randomObject": random_dictionary,
    "randomNumber": random_number,
    "randomName": random_name,
  }

  try:
    response = requests.post(url, params)
    data = response.json()
  except Exception as e:
    print(e)
  else:
   return data

Right now I’m getting the following error from the API endpoint:

{'error': '"randomObject" must be of type object'}

Answer

I finally realized that I needed to pass it as json instead of param:

def do_random_request(self, random_dictionary: dict, random_number: int, random_name: str):
  url = "https://api.random-site.com/"
  json = {
    "randomObject": random_dictionary,
    "randomNumber": random_number,
    "randomName": random_name,
  }