Created
December 15, 2010 21:15
-
-
Save wesrog/742621 to your computer and use it in GitHub Desktop.
Simple Discogs Python API Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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