Difference between revisions of "Generate API request with Python"
From MyWiki
Line 20: | Line 20: | ||
print(response.json()) | print(response.json()) | ||
</source> | </source> | ||
+ | |||
+ | This is data and not json:<br> | ||
+ | https://apidog.com/blog/python-post-request/<br> |
Revision as of 23:56, 9 December 2024
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/