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