gpt4 book ai didi

python - Azure异常: HTTPSConnectionPool : Max retries exceeded with url

转载 作者:行者123 更新时间:2023-12-03 04:19:22 39 4
gpt4 key购买 nike

我正在尝试在本地使用 python 将 csv/pdf 文件上传到 azure blob 存储。

我关注了这个post ,但这会引发错误,

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')
)

上传后我想使用上传的文件来处理。

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)'))

最佳答案

您可以尝试以下更改吗?

a) 添加缺少的导入:

from azure.storage.blob import PublicAccess

b) 如果您使用的是 Azure 存储模拟器,请按如下方式创建 block Blob 服务:

block_blob_service = BlockBlobService(is_emulated=True)

c) 将容器名称更改为 cn1,而不是 mycontainer,这是在代码早期创建的:

block_blob_service.create_blob_from_path(
'cn1',
'C:/temp/blob.csv',
'C:/temp/blob.pdf',
content_settings=ContentSettings(content_type='application/CSV'))

此外,请确保:

a) Azure 存储模拟器正在本地测试期间运行。欲了解更多详情,请访问 https://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator .

b) 通过使用存储资源管理器 ( https://azure.microsoft.com/en-us/features/storage-explorer/ ) 打开,您可以获得正确的存储帐户名称和 key 。

在上述更改之后,我能够使用适当的方法签名在 Azure 存储模拟器和 Azure 本身上运行脚本来创建 block blob 服务。

关于python - Azure异常: HTTPSConnectionPool : Max retries exceeded with url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50528704/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com