azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

Unhandled additional path delimiter for account url in BlobServiceClient

Open harneetvirk opened this issue 3 years ago • 1 comments
trafficstars

  • azure-storage-blob:
  • 12.13.0:
  • Windows:
  • Python 3.8:

Describe the bug There is an unhandled additional path delimiter for account url in BlobServiceClient. This is causing a problem in parsing account_url in BlobServiceClient, because our application presumes to send the account url with resource identifier as '/subscriptions/SOME SUBSCRIPTION/resourceGroups/SOME RG/providers/Microsoft.Storage/storageAccounts/SOME STORAGE', but BlobServiceClient cannot parse the account_url with three slashes generated after concatenation of https:// + account_url

storage_account_key = 'REDACTEDKEY' storage_account_full='/subscriptions/subscriptionID/resourceGroups/RGID/providers/Microsoft.Storage/storageAccounts/STORAGENAME' blob_service_client = BlobServiceClient(account_url=storage_account_full, credential={"account_name": storage_account, "account_key": storage_account_key}) Traceback (most recent call last): File "", line 1, in File "C:\Users\harnvir\Miniconda3\envs\py38storage\lib\site-packages\azureml_vendor\azure_storage\blob_blob_service_client.py", line 132, in init raise ValueError("Invalid URL: {}".format(account_url)) ValueError: Invalid URL: https:**///**subscriptions/subscriptionID/resourceGroups/RGID/providers/Microsoft.Storage/storageAccounts/STORAGENAME

The issue is happening at this point where https is appended to account_url account_url = "https://" + account_url

https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py#L129

harneetvirk avatar Sep 23 '22 05:09 harneetvirk

Hi @harneetvirk Harneet, I believe that there may be some confusion on what is happening here. While I see that the parsing logic is a little less than perfect, I believe the issue of having three /// characters can be alleviated by chopping off the prefixed / before passing it to our parser.

However, even if that is done, making your account_url string look like the following: https://subscriptions/subscriptionID/resourceGroups/RGID/providers/Microsoft.Storage/storageAccounts/STORAGENAME

This would likely still lead to an error as this is the not the expected value for the account_url parameter.

Typically, account_url is in the form: https://<account_name>.<endpoint_type>.core.windows.net Where <account_name> would be your Storage account name (which can be located under 'Access keys' in Azure Portal) image And <endpoint_type> refers to the endpoint (i.e. blob (blob), dfs (datalake), etc.)

So in this case, if your account_name was harneetvirk and you are using the azure-storage-blob package, the account_url parameter is expected to be: https://harneetvirk.blob.core.windows.net

With that being said, hopefully that clears up any confusion! Thanks!

vincenttran-msft avatar Sep 26 '22 22:09 vincenttran-msft