2015-06-12 31 views
0

我试图将我的django应用程序的静态文件同步到Azure存储。在运行manage.py collectstatic命令时,我尝试将静态文件写入存储容器时出现错误。Azure存储容器API请求认证与Django应用程序失败

我收到错误。在HTTP请求中找到的MAC签名与任何计算签名都不相同。

此错误的常见原因是两个服务器上不匹配的时间签名,但这不是我的情况的问题。

我使用Django的包django-azure-storageazure-sdk-for-python格式化请求。

http请求,并试图连接到天青储存容器时所产生的响应的Here is a gist

这些输出有什么看起来不对吗?

+0

你能分享你的代码吗?我倾向于认为该错误与内容类型的请求标题有关。 –

+0

代码可以在上面链接的django-azure-storage repo中找到。 – rawbeans

回答

1

我已经下载了Django的包,下面你的描述Azure的SDK。我编写了一个样本来重现此问题,但它在我身边正常工作。以下是我所做的步骤: 设置环境:Python 2.7和Azure SDK(0.10.0)。

1.Trying使用Django的Azure的存储 这是非常令人沮丧的,我并没有将其导入到我的项目成功,因为这是我第一次用它。通常,我利用Azure Python SDK directly。这次我在我的项目中复制了storage.py作为AzureStorage类。

#need import django contentfile type 
from django.core.files.base import ContentFile 

#import the AzureStorage Class form my project 
from DjangoWP.AzureStorage import AzureStorage 
# my local image path 
file_path="local.png"; 
# my Azure storage blob file 

def djangorplugin(): 
    azurestorage=AzureStorage(myaccount, mykey,"mycontainer") 

    stream=open(file_path, 'rb')  
    data = stream.read() 
    #need convert file to ContentFile 
    azurestorage.save("Testfile1.png",ContentFile(data)) 

enter image description here 2.You很多想知道如何使用Azure的SDK的Python直接,下面的代码片段供大家参考:

from azure.storage.blobservice import BlobService 
#my local image path 
file_path="local.png"; 
def upload(): 
    blob_service = BlobService(account_name=myaccount, account_key=mykey) 
    stream=open(file_path, 'rb')  
    data = stream.read() 
    blob_service.put_blob("mycontainer","local.png",data,"BlockBlob") 

如果您有任何疑虑,请随时让我们知道。

0

我错误地使用设置DEFAULT_FILE_STORAGE而不是STATICFILES_STORAGE来覆盖同步静态文件时使用的存储后端。改变这个设置解决了这个问题。

试图使用django-storages,其指定使用的DEFAULT_FILE_STORAGE设置它的文档时,我也遇到了问题。但是,使用此包对STATICFILES_STORAGE也解决了我遇到的问题。