Azure / Azure/azure-storage-python

BaseBlobService.get_blob_to_stream doesn't accept io.StringIO as a stream

未关闭
#536 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
343
派生
243
PR 合并指标
30 天内没有已合并 PR

描述

### Which service(blob, file, queue) does this issue concern?

Blob

### Which version of the SDK was used? Please provide the output of `pip freeze`.

```
azure-storage-blob==1.4.0
azure-storage-common==1.4.0
azure-storage-file==1.4.0
azure-storage-nspkg==3.0.0
azure-storage-queue==1.4.0
```

### What problem was encountered?

```python
from azure.storage.blob.baseblobservice import BaseBlobService
import io

file_uri = "..."
blob_service = BaseBlobService(connection_string="...")

string_stream = io.StringIO()
string_result = blob_service.get_blob_to_stream("...", "....csv", stream=string_stream)
```

Fails with:
```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
1 string_stream = io.StringIO()
----> 2 string_result = blob_service.get_blob_to_stream("...", ".....csv", stream=string_stream)
3 #print("content type: {}".format(type(string_stream)))

~/miniconda3/envs/py36/lib/python3.6/site-packages/azure/storage/blob/baseblobservice.py in get_blob_to_stream(self, container_name, blob_name, stream, snapshot, start_range, end_range, validate_content, progress_callback, max_connections, lease_id, if_modified_since, if_unmodified_since, if_match, if_none_match, timeout)
2052 # Clear blob content since output has been written to user stream
2053 if blob.content is not None:
-> 2054 stream.write(blob.content)
2055 blob.content = None
2056

TypeError: string argument expected, got 'bytes'
```

Even though accordin to the docs the [stream param](https://azure-storage.readthedocs.io/ref/azure.storage.blob.baseblobservice.html?highlight=get_blob_to_stream#azure.storage.blob.baseblobservice.BaseBlobService.get_blob_to_stream) is an `io.IOBase` and `issubclass(io.StringIO, io.IOBase)` is `True`.
Am I missing something?

贡献指南

打开贡献指南

调研方向

从 azure/storage/blob/baseblobservice.py 中的 BaseBlobService.get_blob_to_stream 开始,检查 traceback 中显示的 stream.write(blob.content) 路径。使用 io.StringIO 和文档所述的 stream 参数重现该故障,然后验证受支持的 stream 行为已由回归测试覆盖,并且 StringIO 情况不再引发报告的 TypeError。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
cloud
Issue 类型
缺陷
难度
2/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。