我要求关注google drive api下载文件内容 https://www.googleapis.com/drive/v3/files/fileId?alt=media
我收到了以下回复标题:
import xml.sax
def stream_gz_decompress(stream) :
dec = zlib.decompressobj(32 + zlib.MAX_WBITS)
for chunk in stream :
rv = dec.decompress(chunk)
if rv :
yield rv
class stream_handler(xml.sax.handler.ContentHandler) :
last_entry = None
last_name = None
def startElement(self, name, attrs) :
self.last_name = name
if name == 'item':
self.last_entry = {}
elif name != 'root' and name != 'updated' :
self.last_entry[name] = {'attrs': attrs, 'content': ''}
def endElement(self, name):
if name == 'item':
# YOUR APPLICATION LOGIC GOES HERE
self.last_entry = None
elif name == 'root':
raise StopIteration
def characters(self, content):
if self.last_entry:
self.last_entry[self.last_name]['content'] += content
parser = xml.sax.make_parser()
parser.setContentHandler(stream_handler())
with open(os.path.basename('FILENAME'), "rb") as local_file:
for data in stream_gz_decompress(local_file):
parser.feed(data)
在回复身体编码的pdf文件中是这样的:
Status Code: 200 OK
Alt-Svc: quic=":443"; ma=2592000; v="37,36,35"
Cache-Control: private, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Length: 539096
Content-Type: application/pdf
Date: Thu, 23 Mar 2017 06:45:35 GMT
Expires: Thu, 23 Mar 2017 06:45:35 GMT
Server: UploadServer
Vary: Origin, X-Origin
Warning: 214 UploadServer gzipped
X-Firefox-Spdy: h2
x-guploader-uploadid: AEnB2Ur3pm8DuMyKmFwS83qzuZZtsEG-WBzyq5pAEA-B3gzUFF7vJgpDr1FuHTH29dmH3qi-Cw8GRIBetNkp0cOi9SXZ2vs3yw
如何在可读的pdf文件中查看此响应。 感谢。