chatgpt/pastedb/example_post_paste2org.py

20 lines
569 B
Python

import requests
# Set the URL of the Paste2.org API endpoint
url = 'https://paste2.org/'
# Get the input from the user
text = 'Enter text to upload'
# Send the HTTP POST request to the Paste2.org API with the text as the request body
response = requests.post(url, data=text.encode('utf-8'))
# Get the URL of the uploaded text from the response JSON
if response.status_code == 200:
paste_id = response.json().get('id')
paste_url = f'https://paste2.org/{paste_id}'
print('Uploaded to:', paste_url)
else:
print('Error uploading text:', response.text)