python我如何从http请求中逐行读取gzip文件



现在我的情况是这样的。我通过请求模块请求gzip文件(它的大小很大,所以我使用流选项(。解压缩这个gz文件,它是dictonary.txt。然后我想在读取gz.file时读取这个字符串(http-get(。像这个

with r.get(url,stream='true') as res:
#gz file is big so read by iter_content
for chunk in res.iter_content(chunck_size=512)
#I get an error in the below part, I want read str Line
extracted = gzip.decompress(chunk)
for line in extracted.split(b'n'):
line = line.decode() 
import requests
import gzip
with requests.get(url,stream=True) as res:
extracted = gzip.decompress(res.content)
for line in extracted.split(b'n'):
line = line.decode()

相关内容

  • 没有找到相关文章

最新更新