def load_xml(self): """ fetches a copy of the response XML provided by the discogs api. See here http://www.discogs.com/help/api for docs. """ print 'request: ' + self.url request = urllib2.Request(self.url) request = utils.req_add_headers(request) try: response = urllib2.urlopen(request) data = response.read() relxml = minidom.parseString(gzip.GzipFile(fileobj = \ cStringIO.StringIO(data)).read()) except Exception: try: # retrying to get the XML, but treating the result as plain text, # not gzipped response = urllib2.urlopen(request) data = response.read() relxml = minidom.parseString(data) except Exception: sys.stderr.write(("err: unable to obtain Discogs release id%s\n") % self.relId) sys.exit(1) return relxml
def loadXml(self): """ fetches a copy of discogs xml for further processing """ request = urllib2.Request(self.url) request = utils.req_add_headers(request) try: response = urllib2.urlopen(request) data = response.read() axml = minidom.parseString(gzip.GzipFile(fileobj =\ cStringIO.StringIO(data)).read()) except IOError: axml = minidom.parseString(data) except Exception: sys.stderr.write(u"err: unable to fetch artist \"%s\"" %\ self.discogsName.decode('utf-8')\ +\ u" information from discogs db\n") sys.exit(1) return axml