Make Short URLs with Python and

Hi, on an application im working on that generates very long urls and need to show it easy for users i thinked on some online services that generates short URLs like or and come with that script to make the urls shorten from Python programing language, i decided to use service as im a huge Google fan. Here is the code i wrote and hopes can be usefull for someone

import re
from urllib import quote
from urllib2 import urlopen, Request, HTTPError
import simplejson as json

def make_short_url(url):
  Shorten a URL with
  if not re.match('http://',url):
    raise Exception('Invalid URL')
  except HTTPError, e:
    json = json.loads(
    if 'short_url' not in json:
      raise Exception('Server has returned Invalid Response')
    return json['short_url']
  raise Exception('Unknown error has Ocurred.')