question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

For Azure stream, including the opened variable in a formatted message throws an exception

See original GitHub issue

Problem 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:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
TonyBjerstedtTRcommented, Apr 26, 2022

Upgraded to 6.0.0 as requested. This appears to be fixed. Program displays:

(.venv) PS C:\projects\test\smotest> python print-client.py
Opened (Reader, 'truccr-normalized-data', 'all-providers/warning-lights/2022-04_approved-exemptions.json')
0reactions
mpenkovcommented, Apr 27, 2022

Great to hear, thank you for letting us know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Everything you wanted to know about exceptions - PowerShell
An Exception is like an event that is created when normal error handling can't deal with the issue. Trying to divide a number...
Read more >
Handle errors and exceptions in Azure Logic Apps
When an action throws an unhandled error or exception, the action is marked Failed, and any successor action is marked Skipped. If this...
Read more >
Manage exceptions with the debugger in Visual Studio
With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window. Provide handlers that ......
Read more >
Azure Stream Analytics resource log data errors
This article explains the different input and output data errors that can occur when using Azure Stream Analytics.
Read more >
Troubleshoot Azure Automation runbook issues
This article tells how to troubleshoot and resolve issues with Azure Automation runbooks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found