Skip to content

Instantly share code, notes, and snippets.

@wesrog
Created December 15, 2010 21:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesrog/742621 to your computer and use it in GitHub Desktop.
Save wesrog/742621 to your computer and use it in GitHub Desktop.
Simple Discogs Python API Client
import urllib2, gzip, cStringIO
url = 'http://www.discogs.com/release/123?f=xml&api_key=1111'
headers = {'Accept-Encoding': 'gzip', 'User-Agent': 'MyDiscogsClient/1.0 +http://mydiscogsclient.org'}
request = urllib2.Request(url, None, headers)
try:
response = urllib2.urlopen(request)
data = response.read()
try:
data = gzip.GzipFile(fileobj = cStringIO.StringIO(data)).read()
except IOError:
pass
except urllib2.HTTPError, e:
data = e.read()
print data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment