MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.26k stars 21.43k forks source link

Error in "Getting Started" Python example "get_blob_service_client_sas" #120501

Closed mborus closed 7 months ago

mborus commented 7 months ago

Trying to learn enough about azure to simply upload a file when I have an URL and a SAS_TOKEN

So I'm trying your getting started documentation

The function get_blob_service_client_sas( has "self" as the first parameter, but is not a class function.

This is a non working getting started code, which is quite frustrating.

If I remove the "self", I get the error "ImportError: Unable to create async transport. Please check aiohttp is installed."


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

AjayBathini-MSFT commented 7 months ago

@mborus Thanks for your feedback! We will investigate and update as appropriate.

ManoharLakkoju-MSFT commented 7 months ago

Hi @mborus I'd recommend working closer with our support team via an [Azure support request] (https://docs.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request). Or you can leverage our Q&A forum by posting your issue there so our community, and MVPs can further assist you in troubleshooting this issue or finding potential workarounds.

[Teams Q&A forum] (https://docs.microsoft.com/en-us/answers/topics/46488/office-teams-windows-itpro.html) for technical questions about the configuration and administration of Microsoft Teams on Windows. [Microsoft Teams Community forum] (https://answers.microsoft.com/en-us/msteams/forum?sort=LastReplyDate&dir=Desc&tab=All&status=all&mod=&modAge=&advFil=&postedAfter=&postedBefore=&threadType=All&isFilterExpanded=false&page=1) Thank you for your time and patience throughout this issue.

mborus commented 7 months ago

@ManoharLakkoju-MSFT Thanks for your reply. I managed to solve this for me by asking on stackoverflow and discussing the answer with ChatGPT afterwards. At this point I'm not looking for help for myself.

I wanted to let you know that the examples you give for Python (non-async) in your documentation do not work. It would make sense to verify that the examples, so that other users have a better experience when they try the same thing.

pauljewellmsft commented 7 months ago

@mborus Thanks so much for your feedback, and I'm sorry you ran into an issue with the documentation. I noticed that one of the error messages above mentions aiohttp. If you're just trying to use synchronous methods to upload a blob, then you won't need to import any async libraries. Could that be part of the issue?

Here's the test I just tried using the get_blob_service_client_sas method from the docs:

from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient

class AuthSamples(object):

    def get_blob_service_client_sas(self, sas_token: str):
        # TODO: Replace <storage-account-name> with your actual storage account name
        account_url = "https://<storage-account-name>.blob.core.windows.net"
        # The SAS token string can be assigned to credential here or appended to the account URL
        credential = sas_token

        # Create the BlobServiceClient object
        blob_service_client = BlobServiceClient(account_url, credential=credential)

        return blob_service_client

if __name__ == '__main__':
    sample = AuthSamples()
    blob_service_client = sample.get_blob_service_client_sas(sas_token="<add_sas_here>")

    # Now we can use the client object to interact with the storage account

After updating the placeholder values with my own, the code works for me. It sounds like you've already solved your issue, but please let us know if you have further feedback.

ManoharLakkoju-MSFT commented 7 months ago

@pauljewellmsft Thanks for your inputs

@mborus if there are any further questions regarding the documentation, please tag me in your reply and we will be happy to continue the conversation.