For Azure stream, including the opened variable in a formatted message throws an exception
See original GitHub issueProblem description
We are using smart_open
to read Azure blobs in an Azure function (but this happens locally as well). When trying to show the opened steam in log messages (f'{opened_stream}'
), the logging code fails with the following exception:
Exception has occurred: AttributeError ‘Reader’ object has no attribute ‘_container’ File “C:\projects\test\smotest\print-client.py”, line 14, in main print(f’Opened {stream}') File “C:\projects\test\smotest\print-client.py”, line 17, in <module> main()
Using the stream variable in a print or log message should display a meaningful output, not throw an exception.
Steps/code to reproduce the problem
Sample reproduction code:
import os
import smart_open
from azure.storage.blob import BlobServiceClient
ACCT = 'https://SOME-STORAGE-ACCT.core.windows.net/'
CONTAINER = 'SOME-CONTAINER'
BLOB = 'SOME-BLOB-PATH'
def main():
client = BlobServiceClient(ACCT, os.environ['STORAGE_ACCOUNT_KEY'])
path = str(f'azure://{CONTAINER}/{BLOB}')
with smart_open.open(path, 'rb', transport_params=dict(client=client)) as stream:
print(f'Opened {stream}')
if __name__ == '__main__':
main()
Versions
import platform, sys, smart_open
print(platform.platform())
print("Python", sys.version)
print("smart_open", smart_open.__version__)
displays:
Windows-10-10.0.19044-SP0 Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] smart_open 5.2.1
Issue Analytics
- State:
- Created a year ago
- Comments:5
Upgraded to 6.0.0 as requested. This appears to be fixed. Program displays:
Great to hear, thank you for letting us know!