· 5 years ago · Sep 13, 2020, 01:42 AM
1
2from urllib.request import urlopen
3import urllib.parse
4
5# Post limit, maximum pastes per 24h = 10 POST req
6
7# To know your API key, sign in to your paste bin account
8# and go to https://pastebin.com/doc_api#1
9PASTEBIN_KEY = 'Your Unique Developer API Key'
10
11
12# code to get a api_user_key
13PASTEBIN_URL = 'https://pastebin.com/api/api_login.php'
14pastebin_vars = dict(
15 api_user_name='USER NAME',
16 api_dev_key=PASTEBIN_KEY,
17 api_user_password='Your PASSWORD',
18)
19
20USER_KEY = urlopen(urllib.request.Request(PASTEBIN_URL, urllib.parse.urlencode(
21 pastebin_vars).encode('utf8'))).read().decode("utf-8")
22
23
24
25# your code goes between (there must be three single qoutes, not two)
26source_code = ''
27
28''
29
30# post request to paste
31PASTEBIN_URL = 'https://pastebin.com/api/api_post.php'
32pastebin_vars = dict(
33 api_user_key=USER_KEY,
34 api_option='paste',
35 api_dev_key=PASTEBIN_KEY,
36 api_paste_name='pastebin_API_python',
37 api_paste_code=source_code,
38 api_paste_format='python',
39)
40
41# data = urllib.parse.urlencode(pastebin_vars)
42# print('data', data)
43# data = data.encode('utf8')
44# print('encoded', data)
45# req = urllib.request.Request(PASTEBIN_URL, data)
46# print('req', req.get_full_url)
47# resp = urlopen(req)
48# print('resp', resp.read())
49
50print(urlopen(urllib.request.Request(PASTEBIN_URL,
51 urllib.parse.urlencode(pastebin_vars).encode('utf8'))).read().decode("utf-8"))
52
53