使用Python SDK的Azure存储错误 [英] Azure storage error using Python SDK

查看:70
本文介绍了使用Python SDK的Azure存储错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将适用于python的Azure SDK下载到我的Ubuntu(工具版本0.8.16).而且我正在尝试运行此代码

I've download Azure SDK for python to my Ubuntu (Tool version 0.8.16). And i'm trying to run this code

from azure.storage import BlobService
blob_service = BlobService(account_name='Real_Name', account_key='Real_Key')
blob_service.create_container('mycontainer')
blob_service.create_container('mycontainer', x_ms_blob_public_access='container') 

blob_service.put_block_blob_from_path(
    'mycontainer',
    'myblob',
    'sunset.png',
    x_ms_blob_content_type='image/png'
)

我已将其保存在Test.py下,并且尝试使用

I've saved it under Test.py and i'm trying to run it with

python Test.py

在终端中,我收到此错误

in terminal and i get this error

Traceback (most recent call last):
  File "Test.py", line 3, in <module>
    blob_service.create_container('mycontainer')
  File "/home/parallels/azure-sdk-for-python/azure/storage/blobservice.py", line 203, in create_container
    _dont_fail_on_exist(ex)
  File "/home/parallels/azure-sdk-for-python/azure/__init__.py", line 525, in _dont_fail_on_exist
    raise error
azure.WindowsAzureError: Unknown error (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.)
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:98ce37f9-0001-003f-350e-7d3666000000
Time:2015-03-24T10:07:00.3385327Z</Message><AuthenticationErrorDetail>Request date header too old: 'Tue, 24 Mar 2015 09:06:59 GMT'</AuthenticationErrorDetail></Error>

如何解决此问题,我做对了吗?

How to fix this, and am i do everything right?

谢谢

推荐答案

如错误中所述:

请求日期标头太旧:"2015年3月24日星期二,格林尼治标准时间"

Request date header too old: 'Tue, 24 Mar 2015 09:06:59 GMT'

如果计算机上的日期/时间(以UTC为单位)与Azure存储服务器上的日期/时间之间的差异超过15-20分钟(您的计算机的日期/时间晚于Azure的日期/时间),则会收到此错误.

You will get this error if difference between the date/time on your computer (in UTC) and date/time on Azure Storage Server is more than 15-20 minutes (your computer's date/time is behind that of Azure).

更新

基本上,发生的情况是,将请求发送到Azure存储服务(例如,创建容器)时,SDK会获取计算机的本地日期/时间,将其转换为UTC,然后将其与请求一起发送到Azure(如日期或x-ms-date的请求标头).收到请求后,Azure存储服务会将该日期/时间与其日期/时间进行比较,如果两者之间的差异超过15-20分钟(您的时钟落后),则Azure存储服务会引发您得到的错误.这样做是一种安全措施,以防万一有人抓住您的请求而无法一遍又一遍地重播该请求.

Essentially what happens is that when a request is sent to Azure Storage Service (e.g. create container) the SDK takes the local date/time of your computer, converts it into UTC and then sends it to Azure along with the request (as a request header either date or x-ms-date). Upon receiving the request, among other things Azure Storage service compares this date/time with its date/time and if the difference is more than 15-20 minutes (your clock is behind), Azure Storage service throws the error you're getting. This is done as a security measure so that in case somebody got hold of your request can't replay the request over and over again.

这篇关于使用Python SDK的Azure存储错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆