chatgpt/pastedb/example_post_snippet.py

19 lines
472 B
Python
Raw Normal View History

import requests
url = "https://snippet.host/api/documents"
# Text to be pasted
text = "Hello, world!"
# Create a new paste
response = requests.post(url, data=text)
if response.status_code == 200:
# Extract the URL of the newly created paste
paste_url = f"https://snippet.host/{response.json()['key']}"
print(f"Paste URL: {paste_url}")
else:
# If the response code is not 200, print the response body for debugging
print(f"Error: {response.text}")