Intro
In this blog, I am going to show how to post JSON information in Python console.
Software requirement
Python 3.5 and IDLE (Python 3.5)
Programming code
-
-
- import requests
- import simplejson as json
-
- url="https://www.googleapis.com/urlshortener/v1/url"
-
- payload={"longUrl": "http://www.google.com/"}
-
- headers={"Content-Type: application/json"}
-
- r= requests.post(url, json=payload)
-
- print(r.text)
About the code
First, I am importing the requests and simplejson modules.
Next, setting a variable and assigning the payload, headers value.
Finally, I have written the request and output statement to show the result in Python console.
Then, let’s execute the code.
Output