对于下面的代码,我收到以下 mypy 错误。如何正确转换响应对象,以便 mypy 对我将其传递给 shutil.copyfileobj 方法感到满意?
error:Argument 1 to "copyfileobj" has incompatible type "Union[HTTPResponse, BinaryIO]"; expected IO[Any]
以下代码将来自 Web 请求的响应流式传输到文件。
request = urllib.request.Request(get_file_url, headers=self.data_api_headers)
with urllib.request.urlopen(request) as response:
with open(export_file_path, 'wb') as out_file:
shutil.copyfileobj(response, out_file)