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