· 6 years ago · Apr 28, 2020, 10:06 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_dev_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
9
10# My session key.
11# Got it from https://pastebin.com/api/api_login.php
12# with 3 parameters: api_dev_key, api_user_name, api_user_password
13api_user_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
14
15# Your code that you want to upload to pastebin
16source = 'print("Hello Pastebin")'
17
18# Data to be sent to API
19data = {"api_dev_key": api_dev_key,
20 "api_option": "paste",
21 "api_paste_code": source,
22 "api_paste_format": "python",
23 "api_paste_expire_date": "N", # Never expire
24 "api_paste_private": 0, # Public
25 "api_paste_name": "Create a paste as a logged in user",
26 "api_user_key": api_user_key}
27
28# Sending post request and saving response as a response object (r)
29r = requests.post(url=api_endpoint, data=data)
30print("The Pastebin URL:", r.text)