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