· 6 years ago · Apr 28, 2020, 04:50 AM
1
2import requests
3
4# API endpoint
5api_endpoint = "https://pastebin.com/api/api_post.php"
6
7# Get your API key (not mine) by logging into your account
8api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
9
10# Your code that you want to upload to pastebin
11source = 'print("Hello Pastebin")'
12
13# Data to be sent to API
14# 3 Required Parameters: api_dev_key, api_option, api_paste_code
15data = {"api_dev_key": api_key,
16 "api_option": "paste",
17 "api_paste_code": source,
18 "api_paste_format": "python",
19 "api_paste_expire_date": "N", # Never expire
20 "api_paste_private": 0, # Public
21 "api_paste_name": "My first POST request in Python"}
22
23# Sending post request and saving response as a response object (r)
24r = requests.post(url=api_endpoint, data=data)
25print("The Pastebin URL:", r.text)