· 5 years ago · Sep 18, 2020, 03:50 AM
1
2# importing the requests library
3import requests
4
5# defining the api-endpoint
6API_ENDPOINT = "http://pastebin.com/api/api_post.php"
7
8# your API key here
9API_KEY = "XXXXXXXXXXXXXXXXX"
10
11# your source code here
12source_code = '''
13print("Hello, world!")
14a = 1
15b = 2
16print(a + b)
17'''
18
19# data to be sent to api
20data = {'api_dev_key':API_KEY,
21 'api_option':'paste',
22 'api_paste_code':source_code,
23 'api_paste_format':'python'}
24
25# sending post request and saving response as response object
26r = requests.post(url = API_ENDPOINT, data = data)
27
28# extracting response text
29pastebin_url = r.text
30print("The pastebin URL is:%s"%pastebin_url)
31