私は安静のエンドポイントを持っています。私の残りのAPIはそれにリクエストを出し、そのファイルはzipファイルです。このzipファイルには2つのファイルがあります。私はこのzipアーカイブから1つのファイルの内容を読みたいだけです。私はテストをすることができたし、私のコードがline file = zipfile.ZipFile(io.BytesIO(response_object.content))にスタックしているのが好きです。Pythonは、API呼び出しからファイルを読み込みます。
クラスZipFileResponseHandler:
def __init__(self,**args):
self.csv_file_to_index = args['csv_file_to_index']
def __call__(self, response_object, raw_response_output, response_type, req_args, endpoint):
file = zipfile.ZipFile(io.BytesIO(response_object.content))
for name in file.namelist():
if re.match(name, self.csv_file_to_index):
data =file.read(name)
print_xml_stream(repr(data))