Generate API request with Python
From MyWiki
https://www.datacamp.com/tutorial/making-http-requests-in-python?dc_referrer=https%3A%2F%2Fwww.google.com%2F
This uses json:<>
import requests # The API endpoint url = "https://jsonplaceholder.typicode.com/posts" # Data to be sent data = { "userID": 1, "title": "Making a POST request", "body": "This is the data we created." } # A POST request to the API response = requests.post(url, json=data) # Print the response print(response.json())
This is data and not json:
https://apidog.com/blog/python-post-request/
import requests # Define the URL and the data to be sent in the POST request url = 'http://example.com/test/demo_form.php' data = {'name1': 'value1', 'name2': 'value2'} # Make the POST request response = requests.post(url, data=data) # Print the status code and the response content print(f"Status Code: {response.status_code}") print(f"Response Content: {response.text}")