【发布时间】:2021-11-29 08:23:25
【问题描述】:
I am a novice in Python programming and trying to create a blob container using python. Even after following the documented steps, I see the below error.
Here is my code:
import os, uuid
from azure.storage.blob import BlobServiceClient,BlobClient,ContainerClient,__version__
class BlobSamples():
print("Azure Blob Storage v" + __version__ + " - Python quickstart sample")
connection_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
print("Connection established to Azure storage account from the Python App")
#--Begin Blob Samples-----------------------------------------------------------------
def create_container_sample(self):
# Instantiate a new BlobServiceClient using a connection string
blob_service_client = BlobServiceClient.from_connection_string(self.connection_str)
# Instantiate a new ContainerClient
container_client = blob_service_client.get_container_client("mycontainer")
try:
# Create new container in the service
container_client.create_container()
# List containers in the storage account
list_response = blob_service_client.list_containers()
except Exception as ex:
print('Exception:')
print(ex)
#main program
sample = BlobSamples()
sample.create_container_sample()
**Error:**
py ConnectionString.py
Azure Blob 存储 v12.9.0 - Python 快速入门示例
从 Python 应用程序建立到 Azure 存储帐户的连接
回溯(最近一次通话最后):
文件“C:\Technical docs\cloud Computing\MS Azure\blob-quickstart-v12\menu-driven-strg-ops\ConnectionString.py”,第 31 行,在
sample.create_container_sample()
文件“C:\Technical docs\cloud Computing\MS Azure\blob-quickstart-v12\menu-driven-strg-ops\ConnectionString.py”,第 16 行,在 create_container_sample
blob_service_client = BlobServiceClient.from_connection_string(self.connection_str)
文件“C:\Python-InstallPath\lib\site-packages\azure\storage\blob_blob_service_client.py”,第 174 行,在 from_connection_string
enter code hereaccount_url, 二级, 凭证 = parse_connection_str(conn_str, 凭证, 'blob')
parse_connection_str 中的文件“C:\Python-InstallPath\lib\site-packages\azure\storage\blob_shared\base_client.py”,第 363 行
conn_str = conn_str.rstrip(";")
AttributeError:“NoneType”对象没有属性“rstrip”
【问题讨论】:
-
你能试试把
self.connection_str改成connection_str吗? -
blob_service_client = BlobServiceClient.from_connection_string(connection_str) NameError: name 'connection_str' is not defined ----如果我们不使用 self 调用它就不起作用
标签: python azure-blob-storage azure-sdk-python