Azure nối thêm blob ví dụ python

def upload_object_to_container[ self, block_blob_client, container_name, blob_name, obj ]. """ Tải tệp cục bộ lên bộ chứa lưu trữ Azure Blob. . tham số block_blob_client. Một khách hàng dịch vụ blob. . gõ block_blob_client. `màu xanh. kho. bãi. BlockBlobService`. tham số str container_name. Tên của bộ chứa lưu trữ Azure Blob. . tham số str file_path. Đường dẫn cục bộ đến tệp. . đánh máy. `màu xanh. lô hàng. người mẫu. Tệp tài nguyên`. trở về. Một ResourceFile được khởi tạo với một SAS URL thích hợp cho các tác vụ Batch. """ # print["Đang tải tệp {} lên vùng chứa [{}]. ". định dạng [blob_name, container_name]] block_blob_client. create_blob_from_text[ container_name, blob_name, dump[obj, Dumper=Dumper] ] sas_token = block_blob_client. generate_blob_shared_access_signature[ container_name, blob_name, permission=azureblob. BlobQuyền. ĐỌC, hết hạn = datetime. ngày giờ. utcnow[] + ngày giờ. timedelta[giờ=tự. cấu hình. STORAGE_ACCESS_DURATION_HRS], ] sas_url = block_blob_client. make_blob_url[ container_name, blob_name, sas_token=sas_token ] trả về các mô hình. ResourceFile[http_url=sas_url, file_path=blob_name]

Dịch vụ lưu trữ Azure blob với Khối nối thêm trong mô-đun Azure Azure không hoạt động. Khi tôi cố sửa đổi mô-đun, nó hiển thị lỗi bên dưới

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
  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.]
AuthenticationFailedServer 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.9779810ZThe 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

Có bất kỳ khả năng để giải quyết lỗi này?

Đây là những thay đổi mã của tôi trong mô-đun do SDK cung cấp

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,
        ]

và tôi đã xác định đoạn mã dưới đây trong 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

Xin lưu ý hai tham số bổ sung ở cuối. Tôi đã bao gồm điều này sau khi giới thiệu tài liệu tham khảo api. Đồng thời sửa đổi phiên bản thành X_MS_VERSION = '2015-02-21'

Chủ Đề