Reputation: 871
I am trying to upload a csv/pdf files to azure blob storage using python locally.
I followed this post, but this throws an error,
from azure.storage.blob import BlockBlobService
from azure.storage.blob import ContentSettings
block_blob_service = BlockBlobService(account_name='account_name', account_key='key1')
block_blob_service.create_container('cn1')
block_blob_service.set_container_acl('cn1', public_access=PublicAccess.Container)
#Upload the CSV file to Azure cloud
block_blob_service.create_blob_from_path(
'mycontainer',
'C:/uploads/blob.csv',
'C:/uploads/blob.pdf',
content_settings=ContentSettings(content_type='application/CSV')
)
After uploading i want to use the uploaded file to process.
Traceback (most recent call last):
File "", line 1, in block_blob_service.create_container('cn1')
File "c:\users\rb287jd\appdata\local\programs\python\python36\lib\site-packages\azure\storage\blob\baseblobservice.py", line 600, in create_container self._perform_request(request)
File "c:\users\rb287jd\appdata\local\programs\python\python36\lib\site-packages\azure\storage\storageclient.py", line 280, in _perform_request raise ex
File "c:\users\rb287jd\appdata\local\programs\python\python36\lib\site-packages\azure\storage\storageclient.py", line 252, in _perform_request raise AzureException(ex.args[0])
AzureException: HTTPSConnectionPool(host='account_name.blob.core.windows.net', port=443): Max retries exceeded with url: /cn1?restype=container (Caused by ConnectTimeoutError(, 'Connection to account_name.blob.core.windows.net timed out. (connect timeout=20)'))
Upvotes: 1
Views: 10944
Reputation: 30
If you look at the error: AzureException: HTTPSConnectionPool(host='account_name.blob.core.windows.net', port=443):
This means any of following:
Upvotes: 0
Reputation: 2642
Could you please try the following changes?
a) Add the missing import:
from azure.storage.blob import PublicAccess
b) Create the block blob service as follows if you're using the Azure Storage Emulator:
block_blob_service = BlockBlobService(is_emulated=True)
c) Change the container name to cn1 instead of mycontainer, which is the one being created early in the code:
block_blob_service.create_blob_from_path(
'cn1',
'C:/temp/blob.csv',
'C:/temp/blob.pdf',
content_settings=ContentSettings(content_type='application/CSV'))
In addition, please make sure:
a) Azure Storage Emulator is running during your local tests. Find more details at https://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator.
b) You have the right storage account name and key by opening using Storage Explorer (https://azure.microsoft.com/en-us/features/storage-explorer/).
I was able to get the script working after the changes mentioned above on both Azure Storage Emulator and Azure itself using the appropriate method signature to create the block blob service.
Upvotes: 0