Azure / Azure/azure-storage-python

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

Open
#536 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
343
Forks
243
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.