Azure Blob存储区SAS令牌缺少服务资源字段

2024-04-27 23:32:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用web界面在我的Azure存储帐户上创建了一个共享访问签名(SAS)令牌。代币看起来像

?sv=xxxx-xx-xx&ss=b&srt=sco&sp=rl&se=xxxx-xx-xxTxx:xx:xxZ&st=xxxx-xx-xxTxx:xx:xxZ&spr=https&sig=xxxxxxxxxxxxxxxxxxxxxx

此处的SAS令牌缺少服务资源的sr字段。我必须手动在查询字符串前面加上sr=b以使事情正常工作。我一定是做错了什么,因为这看起来很挑剔。在

from azure.storage.blob import BlockBlobService
sas_token = "?sv=xxxx-xx-xx&ss=b&srt=sco&sp=rl&se=xxxx-xx-xxTxx:xx:xxZ&st=xxxx-xx-xxTxx:xx:xxZ&spr=https&sig=xxxxxxxxxxxxxxxxxxxxxx"
sas_token = "?sr=b&" + sas_token[1:]

serv = BlockBlobService(account_name='myaccount', sas_token=sas_token)

for cont in serv.list_containers():
    print cont.name

没有sas_token = "?sr=b&" + sas_token[1:]我得到错误:

sr is mandatory. Cannot be empty

如果sr=b字段不是查询中的第一个,我会得到如下身份验证错误

Access without signed identifier cannot have time window more than 1 hour


Tags: tokensssprlxxsassrtse
1条回答
网友
1楼 · 发布于 2024-04-27 23:32:57

Access without signed identifier cannot have time window more than 1 hour

根据此错误消息,您可能需要将过期时间设置为小于1小时。见Windows Azure Shared Access Signature always gives: Forbidden 403。在


我用Python v2.7.12和{a2}(最新版本)获取了您的代码。在我的网站上效果很好。所以,我建议您升级到最新版本,然后再试一次。在

enter image description here

更新:

我追踪了code of Azure Storage SDK for Python,这是我发现的。SDK是一个REST API转换程序,它假定SAS令牌如下所示:

sv=2015-04-05&ss=bfqt&srt=sco&sp=rl&se=2015-09-20T08:49Z&sip=168.1.5.60-168.1.5.70&sig=a39%2BYozJhGp6miujGymjRpN8tsrQfLo9Z3i8IRyIpnQ%3d

如您所见,令牌不包括?。当SDK向azurestoragerest服务发出GET请求时,它将在SAS令牌之前追加?。在

enter image description here

这将导致签名版本的密钥被解析为?sv,然后引发问题。因此,为了避免这种情况,我们应该从SAS令牌中删除?。在

相关问题 更多 >