Reputation: 29
Handle the error while making a connection, below code is not working, tried with incorrect names and password still not giving any error
block_blob_service = BlockBlobService(account_name = account_name,account_key = account_key)
try:
if block_blob_service:
print('connection successful!')
except Exception as e:
print('Please make sure the account name and key are correct.', e)
Upvotes: 1
Views: 449
Reputation: 136146
Following line of code:
block_blob_service = BlockBlobService(account_name = account_name,account_key = account_key)
is actually creating an instance of BlockBlobService
(not sure if creating instance is the correct term :), coming from .Net world) and nothing else.
In order to check if the account name/account key combination is correct, you will actually need to perform an operation on that storage account as there is no Login
kind of operation supported in Azure Storage.
Normally the way I do it is try to list blob containers from that storage account. When listing blob containers, just set the num_results
parameter to 1 as we are only interested in checking the account name/key validity and nothing else.
There are three possible outcomes:
remote name could not be resolved
error.Using these outcomes you can decide whether or not account name/key combination is valid.
Upvotes: 2