answer works fine. But found another solution ;
import requests import json url = 'https://www.googleapis.com/urlshortener/v1/url' data = {'longUrl': 'http://www.google.com/'} headers = {'Content-Type': 'application/json'} r = requests.post(url, data=json.dumps(data), headers=headers)
then
answer = json.loads(r.text)
or
answer = r.json()
Here is the requests package; code and doc
source share