我正在尝试使用适用于 Azure 的 Python SDK 生成容器 SAS 令牌。使用下面的代码,我收到此错误:AuthenticationErrorDetail:Signature fields not well formed.
生成的令牌似乎时间格式不正确 - 这是一个问题吗?如果是,我该如何解决?看起来像这样:se=2021-03-08T17%3A49%3A35Z&sp=rwlacu&spr=https&sv=2020-04-08&sr=c&sig=QhAFl1435SDFGSFDguiPA8%3D
我很确定我应该将 sas_token 与容器 url 连接起来,我已经尝试过了,但仍然出现错误。我是否需要再连接,例如container_url + "?sp=r&st=2021-03-08T12:12:14Z&" + sas_token
?我可以在门户中生成的 SAS 令牌至少看起来更像这样。
import datetime
from azure.storage.blob import ContainerClient, BlobServiceClient, generate_container_sas, \
ResourceTypes, AccountSasPermissions
storage_conn_str = "myconstring fetched from the portal"
blob_service_client = BlobServiceClient.from_connection_string(storage_conn_str)
start = datetime.datetime.utcnow().replace(microsecond=0).isoformat() + "Z"
expiry = (datetime.datetime.utcnow() + datetime.timedelta(hours=3)).replace(microsecond=0).isoformat() + "Z"
sas_token = generate_container_sas(
blob_service_client.account_name,
container_name="containername",
account_key=blob_service_client.credential.account_key,
resource_types=ResourceTypes(container=True, object=True),
permission=AccountSasPermissions(read=True, write=True, list=True, add=True, create=True,
update=True),
start=start,
expiry=expiry,
protocol="https"
)
print(sas_token)
cclient = ContainerClient.from_container_url(
container_url="https://myblob.blob.core.windows.net/containername/",
credential=sas_token)
print(cclient.get_account_information())