错误将BLOB上传到在Azure注册表中运行的Docker容器中的芹菜中的存储帐户



无法将斑点上传到Azure,从Azure(来自Azure Registry(上的Docker容器中运行的任务上的任务上将BLOB上传到Azure。能够从本地芹菜工人中成功上传斑点。

我试图通过将Azure中的访问策略更改为" blob"或"容器"来解决问题,但是这并不能解决问题。在本地芹菜工人上运行任务在所有访问级别的情况下完成而没有错误。我已经确保存在容器并正确拼写。

上传斑点的代码:

block_blob_service = BlockBlobService(account_name='my_storage_account', 
account_key= 'my_storage_key')
directory_main = demo_data['username']
filename = 'demographics.json'
block_blob_service.create_blob_from_text('container_name', directory_main + 
filename, demo_json) 

当我尝试通过容器上传时,我会收到以下错误消息:

azureException('指定的资源不存在。错误代码:Resourcenotfound n

" put"请求有两个区别:

本地:'用户代理':'Azure-Storage/1.4.0-1.5.0(Python Cpython 3.7.3; Windows 10('

容器:'用户代理':'Azure-Storage/1.4.0-1.5.0(Python cpython 3.6.8; linux 4.14.14.111-boot2docker('

另外,在本地运行时,将生成"授权"标头,而从容器中跑步时,该标头丢失了。任何帮助将不胜感激。

追溯:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 385, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/app/factory.py", line 43, in __call__
    return self.run(*args, **kwargs)
  File "/app/tasks.py", line 158, in _download_task
    raise(e)
  File "/app/tasks.py", line 107, in _download_task
    block_blob_service.create_blob_from_text('my_container', directory_main + filename, demo_json)
  File "/usr/local/lib/python3.6/site-packages/azure/storage/blob/blockblobservice.py", line 846, in create_blob_from_text
    timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/azure/storage/blob/blockblobservice.py", line 751, in create_blob_from_bytes
    use_byte_buffer=True
  File "/usr/local/lib/python3.6/site-packages/azure/storage/blob/blockblobservice.py", line 582, in create_blob_from_stream
    timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/azure/storage/blob/blockblobservice.py", line 1101, in _put_blob
    return self._perform_request(request, _parse_base_properties)
  File "/usr/local/lib/python3.6/site-packages/azure/storage/common/storageclient.py", line 430, in _perform_request
    raise ex
  File "/usr/local/lib/python3.6/site-packages/azure/storage/common/storageclient.py", line 358, in _perform_request
    raise ex
  File "/usr/local/lib/python3.6/site-packages/azure/storage/common/storageclient.py", line 344, in _perform_request
    HTTPError(response.status, response.message, response.headers, response.body))
  File "/usr/local/lib/python3.6/site-packages/azure/storage/common/_error.py", line 115, in _http_error_handler
    raise ex
azure.common.AzureMissingResourceHttpError: The specified resource does not exist. ErrorCode: ResourceNotFound
<?xml version="1.0" encoding="utf-8"?><Error><Code>ResourceNotFound</Code><Message>The specified resource does not exist.
RequestId:46ba6512-301e-0061-2e62-2c37b7000000
Time:2019-06-26T21:03:00.0960002Z</Message></Error>

根据我的经验,脚本中有两个可能的错误。

  1. 如果存储帐户中的容器container_name不存在,因此您需要在create_blob_from_text之前首先调用create_container。如果存在,create_container功能将不会对您的工作产生任何负面影响。

    block_blob_service.create_container('container_name')
    block_blob_service.create_blob_from_text('container_name', directory_main + 
    

    文件名,demo_json(

  2. 请参考官方文档Naming and Referencing Containers, Blobs, and Metadata,如果要为斑点设置一些虚拟目录,正确的方法是使用/而不是。因此,如下面的代码。

    directory_main = demo_data['username']
    filename = '/demographics.json' # not 'demographics.json'
    

希望它有帮助。

相关内容

  • 没有找到相关文章

最新更新