我正在使用python下载文件,但是从Google云存储下载文件时出错。
文件元数据如下: content_type:文本/ csv content_encoding:gzip 文件扩展名:*。csv.gz
得到以下异常: exceptions.ContentDecodingError:'已收到内容编码为gzip的响应,但未能对其进行解码。'
使用以下python API下载文件。 blob.download_to_filename(filename,start = 100)
问题: 1.如果源文件具有上述元数据属性,如何下载? (gzip作为内容编码) 2.如何在复制(gsutil cp)时解压缩文件?
答案 0 :(得分:0)
您现在可以通过将Accept-Encoding标头设置为 身份:
导入请求
requests.get('http://XXXXX/',headers = {'Accept-Encoding':'identity'})
替代解决方案解决方案是标准化标头:
if(要求http.Accept-Encoding〜“ gzip”){
set req.http.Accept-Encoding =“ gzip”;
}其他{
未设置要求http.Accept-Encoding;
}
$ gsutil cat gs://bucket/obj.gz> /destination/path/obj.gz