I'm trying to use the pastebin api with docs: python https://pastebin.com/doc_api. Using the urllib library: https://docs.python.org/3/library/urllib.html.
import urllib.request
import urllib.parse
def main():
def pastebinner():
site = 'https://pastebin.com/api/api_post.php'
dev_key =
code = "12345678910, test"
our_data = urllib.parse.urlencode({"api_dev_key": dev_key, "api_option": "paste", "api_paste_code": code})
our_data = our_data.encode()
resp = urllib.request.urlopen(site, our_data)
print(resp.read())
pastebinner()
if __name__ == "__main__":
main()
Here's the error i get:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 214, in urlopen return opener.open(url, data, timeout) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 523, in open response = meth(req, response) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 632, in http_response response = self.parent.error( File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 561, in error return self._call_chain(*args) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 494, in _call_chain result = func(*args) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 641, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 422: Unprocessable entity
Any ideas regarding the reason for getting this error?
bump: I still have no idea please help. bump2: :v
Creating A New Paste, [Required Parameters] Include all the following POST parameters when you request the url: 1. api_dev_key - which is your unique API Developers Key. 2. api_option - set as paste, this will indicate you want to create a new paste. 3. api_paste_code - this is the text that will be written inside your paste. Leaving any of these parameters out will result in an error.
– Jon Doe