- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
Python azure 模块中带有附加 block 的 Azure blob 存储服务不起作用。当我尝试修改模块时,它显示以下错误。
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 106, in exec_file
exec_code(code, file, global_variables)
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 82, in exec_code
exec(code_obj, global_variables)
File "E:\Finons\Sankar\Source\Source\WebsiteTracking\testing.py", line 15, in<module>
blob_service.append_block_blob_from_file(containername,filename,filepath,None)
File "C:\Python27\lib\site-packages\azure\storage\blobservice.py", line 2723, in append_block_blob_from_file
x_ms_lease_id,
File "C:\Python27\lib\site-packages\azure\storage\blobservice.py", line 851, in put_blob self._perform_request(request)
File "C:\Python27\lib\site-packages\azure\storage\storageclient.py", line 179, in _perform_request
_storage_error_handler(ex)
File "C:\Python27\lib\site-packages\azure\storage\__init__.py", line 1186, in _storage_error_handler
return _general_error_handler(http_error)
File "C:\Python27\lib\site-packages\azure\__init__.py", line 551, in _general_error_handler
http_error.respbody.decode('utf-8-sig'))
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:898a6c60-0001-0094-2b99-d6da0d000000 Time:2015-08-14T13:58:54.9779810Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'DAAfD/aLQHqljUS35p7CoX+JBc5lyrPr1twQIQEW0HI='
is not the same as any computed signature. Server used following string to sign: 'PUT
application/octet-stream Charset=UTF-8
是否有可能解决此错误?
这是我在SDK给出的模块中的代码更改。
def append_block_blob_from_file(self, container_name, blob_name, stream,
count=None, content_encoding=None,
content_language=None, content_md5=None,
cache_control=None,
x_ms_blob_content_type=None,
x_ms_blob_content_encoding=None,
x_ms_blob_content_language=None,
x_ms_blob_content_md5=None,
x_ms_blob_cache_control=None,
x_ms_meta_name_values=None,
x_ms_lease_id=None, progress_callback=None,
max_connections=1, max_retries=5, retry_wait=1.0):
_validate_not_none('container_name', container_name)
_validate_not_none('blob_name', blob_name)
_validate_not_none('stream', stream)
if count and count < self._BLOB_MAX_DATA_SIZE:
if progress_callback:
progress_callback(0, count)
data = stream.read(count)
self.put_blob(container_name,
blob_name,
data,
'AppendBlob',
content_encoding,
content_language,
content_md5,
cache_control,
x_ms_blob_content_type,
x_ms_blob_content_encoding,
x_ms_blob_content_language,
x_ms_blob_content_md5,
x_ms_blob_cache_control,
x_ms_meta_name_values,
x_ms_lease_id)
if progress_callback:
progress_callback(count, count)
else:
self.put_blob(
container_name,
blob_name,
None,
'AppendBlob',
content_encoding,
content_language,
content_md5,
cache_control,
x_ms_blob_content_type,
x_ms_blob_content_encoding,
x_ms_blob_content_language,
x_ms_blob_content_md5,
x_ms_blob_cache_control,
x_ms_meta_name_values,
x_ms_lease_id,
)
_upload_blob_chunks(
self,
container_name,
blob_name,
count,
self._BLOB_MAX_CHUNK_DATA_SIZE,
stream,
max_connections,
max_retries,
retry_wait,
progress_callback,
x_ms_lease_id,
_AppendBlobChunkUploader,
)
self.put_block_list(
container_name,
blob_name,
block_ids,
content_md5,
x_ms_blob_cache_control,
x_ms_blob_content_type,
x_ms_blob_content_encoding,
x_ms_blob_content_language,
x_ms_blob_content_md5,
x_ms_meta_name_values,
x_ms_lease_id,
)
我在Init.py
中定义了以下代码class _AppendBlobChunkUploader(_BlobChunkUploader):
def _append_chunk(self, chunk_offset, chunk_data):
range_id = url_quote(_encode_base64('{0:032d}'.format(chunk_offset)))
self.blob_service.put_block(
self.container_name,
self.blob_name,
chunk_data,
range_id,
x_ms_lease_id=self.x_ms_lease_id,x_ms_blob_condition_maxsize=4194304,x_ms_blob_condition_appendpos=chunk_offset
)
return range_id
请注意最后的两个附加参数。我在引用 api 引用后将其包含在内。也将版本修改为X_MS_VERSION = '2015-02-21'
引用链接:https://msdn.microsoft.com/en-us/library/azure/mt427365.aspx
最佳答案
您似乎没有提供put_block
您的描述中的功能详细信息。我检查了Python SDK,没有找到put_block
函数支持这两个参数:x_ms_blob_condition_maxsize
和x_ms_blob_condition_appendpos
在BlobService
类(class)。但是,对于您的场景,我建议您可以使用 Azure Blob REST API 来附加您的 block ,如 Gaurav 所说。同时,从你的错误信息来看,我确信你的签名有问题。我使用了一个简单的代码来构造签名字符串,请引用:
import urllib
import hashlib
import hmac
import base64
import urllib.request
from wsgiref.handlers import format_date_time
from datetime import datetime
from time import mktime
account_name='****'
account_key='*****'
account_container='***'
file_name='**'
file_path='**'
request_url='https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=appendblock'
#https://myaccount.blob.core.windows.net/mycontainer/myblob?comp=appendblock Put
blobLength=0
blockID='**'
#create the authorization header
#how to encode and decode signtostring
def createAuthorizationHeader(canonicalizedString):
storage_account_key = base64.b64decode(account_key)
byte_canonicalizedString=canonicalizedString.encode('utf-8')
signature = base64.b64encode(hmac.new(key=storage_account_key,msg=byte_canonicalizedString, digestmod=hashlib.sha256).digest())
print(signature)
authorization_str="SharedKey "+account_name+":"+signature.decode('utf-8')
print(authorization_str)
return authorization_str
#Construction Sign
def constructSTS(http_verb,Content_Encoding='',Content_Language='',Content_MD5='',Content_Type='',Date='',
If_Modified_Since='',If_Match='',If_None_Match='',length='',
If_Unmodified_Since='',Range='',CanonicalizedHeaders='',CanonicalizedResource=''):
StringToSign=http_verb+'\n'+Content_Encoding+'\n'+Content_Language+'\n'+Content_MD5+'\n'+Content_Type+'\n'+Date+'\n'+If_Modified_Since+'\n'+If_Match+'\n'+If_None_Match+'\n'+length+'\n'+If_Unmodified_Since+'\n'+Range+'\n'+CanonicalizedHeaders+CanonicalizedResource;
print(StringToSign)
return StringToSign
#Construction Canonicalized headers
def constructCanonicalizedHeaders(date):
CanonicalizedHeader="x-ms-date:"+date+"\nx-ms-version:2015-02-21\nx-ms-lease-id:"+blockID+"\nms-blob-condition-appendpos:"+youroffset+"\nx-ms-blob-condition-maxsize:4194304\n"
print(CanonicalizedHeader)
return CanonicalizedHeader
#Construction Canonicalized Resource
def constructCanonicalizedResource():
canonicalizedResource="/"+account_name+"/"+account_container+"/"+file_name+"\ncomp:appendblock"
print(canonicalizedResource)
return canonicalizedResource
#get current date
def getCurrentDate():
now = datetime.now()
stamp = mktime(now.timetuple())
date=format_date_time(stamp)
return date
#Create http request
def createHttpRequest():
date=getCurrentDate()
r=urllib.request.Request(request_url)
canonicalizedString=constructSTS("PUT",CanonicalizedHeaders=constructCanonicalizedHeaders(date),CanonicalizedResource=constructCanonicalizedResource(),length=blobLength)
print(canonicalizedString)
r.add_header('x-ms-version','2015-02-21');
r.add_header('Authorization',createAuthorizationHeader(canonicalizedString))
r.add_header('x-ms-date',date)
r.add_header('Content-Length',blobLength)
r.add_header('x-ms-lease-id',blockID)
r.add_header("x-ms-blob-condition-appendpos",youroffset)
r.add_header("x-ms-blob-condition-maxsize",4194304)
您应该获取 blockblob 长度并使用此请求将 blockblob 数据发送到服务器。
关于python - 在 blob 服务 python 中追加 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32012025/
我正在尝试从 Azure 容器中删除 blob。我能够连接到它并列出此问题中代码后面的所有 blob:Upload and Delete Azure Storage Blob using azure-
我正在尝试从 Azure 容器中删除 blob。我能够连接到它并列出此问题中代码后面的所有 blob:Upload and Delete Azure Storage Blob using azure-
运行我的 azure 函数(用于读取 azure blob 存储)后出现错误。 错误是 ID 0dad768d-36d4-4c1a-85ae-2a5122533b3c fail: Func
运行我的 azure 函数(用于读取 azure blob 存储)后出现错误。 错误是 ID 0dad768d-36d4-4c1a-85ae-2a5122533b3c fail: Func
我正在使用 C# 控制台应用程序 (.NET Core 3.1) 从 Azure Blob 存储读取大量图像文件并生成这些图像的缩略图。新图像将保存回 Azure,并将 Blob ID 存储在我们的数
我没有在网上看到任何有关如何获取位于 BlobContainerClient 内特定目录内的所有 blob 的示例。 以前,我使用的是 Microsoft.Azure.Storage 软件包,但这些软
我正在使用 C# 控制台应用程序 (.NET Core 3.1) 从 Azure Blob 存储读取大量图像文件并生成这些图像的缩略图。新图像将保存回 Azure,并将 Blob ID 存储在我们的数
我没有在网上看到任何有关如何获取位于 BlobContainerClient 内特定目录内的所有 blob 的示例。 以前,我使用的是 Microsoft.Azure.Storage 软件包,但这些软
我正在编写一些代码,允许用户使用麦克风录制自己的声音,然后将录音上传到 Azure Blob 存储。 为了录制音频,我使用类似于下面的代码 let recordedBlobs = []; this.m
当前使用:https://github.com/Azure/azure-sdk-for-go 概述:我当前正在从 azure blob 存储中下载一个 blob,解析该 blob,然后将转录的 blo
正在观看 this video about how to design Tinder ,在 06:50 提出了关于文件与 BLOBS 的观点。 我想知道大二进制文件和 BLOB(二进制大对象)之间有什
目前我有 hibernate JPA HSQLDB 来自动创建我的数据库表。 如何告诉 JPA 或 Hibernate 将字符串保存为 clob/blob 字段?即一个很长的字符串。到目前为止我找不
我有一个一维 NumPy 数组,其中包含一些“坏”值。我想剔除它们。 每个坏值的邻居只是“顽皮”,但我也想剔除它们。 对不良值的可靠测试是询问: arr<0.1 但是,(我能想到的)对于顽皮值的唯一可
查看有关获取 Blob 和获取 Blob 属性的 MSDN 文档。两个请求看起来相同 "https://myaccount.blob.core.windows.net/mycontainer/mybl
我有 2 个 Blob 存储,一个在 eastus,一个在 canadaeast,我想将一个 .vhd 从 eastus 复制到 canadaeast。我去了 eastus,在我想要复制的 blob
所以场景如下: 我有多个 Web 服务实例,用于将 blob 数据写入 Azure 存储。我需要能够根据收到的时间将 blob 分组到容器(或虚拟目录)中。偶尔(最坏的情况是每天)旧的 blob 会被
在 Azure Blobstorage 中,我有 100 个 Blob,但我只想列出前 10 个 Blob。我该怎么做? 我写的{maxResults:1}没有任何效果,它仍然列出了我所有的 Blob
我们当前的代码使用 Azure SDK 1.8,为了生成共享访问签名,它将首先调用 CloudBlobContainer.GetBlobReference(),然后调用 CloudBlob.GetSh
我有大量文件存储在公共(public) Azure blob 容器中,所有这些文件都通过我的 ASP.NET MVC Web 应用程序中的 HTML 直接引用。例如,blob 存储中一个图像的路径如下
我有一个 NodeJS 后端,它使用 Microsoft 的官方 Blob 存储库 (@azure/storage-blob) 来管理我的 Blob 存储: https://www.npmjs.com
我是一名优秀的程序员,十分优秀!