Decompressing an XML in python from an API request -
i trying use api https://neweden-dev.com/zkillboard_api in python.
my code works point:
import xml.etree.elementtree et import urllib2 import gzip import zlib   url = 'https://zkillboard.com/api/kills/characterid/95089021/xml/' request = urllib2.request(url) request.add_header('accept-encoding', 'gzip,deflate')  data = urllib2.urlopen(request) after point, confused.
contents = data.read() f = open("export.xml","w") f.write(contents) f.close() above first step. opening file made me realize compressed (duh).
so point tried 2 things:
f = open("test.xml.gz", "w") f.write(data.read()) f.close() g = gzip.open("test.xml.gz", "rb") file_content = g.read() g.close() which gives me error:
traceback (most recent call last):   file "c:\users\[filepath]", line 19, in <module>     file_content = g.read()   file "c:\python27\lib\gzip.py", line 254, in read     self._read(readsize)   file "c:\python27\lib\gzip.py", line 312, in _read     uncompress = self.decompress.decompress(buf) error: error -3 while decompressing: invalid distance far my next step use zlib:
x = zlib.decompress(data.read()) which gives me error of:
traceback (most recent call last):   file "c:\users\[filepath]", line 15, in <module>     x = zlib.decompress(data.read()) error: error -3 while decompressing data: incorrect header check i know missing super simple here, thoughts? thanks.
 
 
  
Comments
Post a Comment