Azure / Azure/azure-storage-python

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

Đang mở
#536 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
343
Fork
243
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with BaseBlobService.get_blob_to_stream in azure/storage/blob/baseblobservice.py, at the stream.write(blob.content) path shown in the traceback. Reproduce the failure with io.StringIO and the documented stream parameter, then verify that the supported stream behavior is covered by a regression test and that the StringIO case no longer raises the reported TypeError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
cloud
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.