[英]Error uploading blob to storage account from celery in docker container running in azure registry
Unable to upload a blob to azure from a task running on a celery worker in a docker container on Azure (from Azure registry). 无法从Azure上的Docker容器中的芹菜工作者上运行的任务中将blob上传到天蓝色(来自Azure注册表)。 Able to successfully upload blob from local celery worker.
能够成功从本地芹菜工作者上传blob。
I've attempted to resolve the issue by changing the access policy in Azure to "Blob" or "Container" however this did not resolve the issue. 我试图通过将Azure中的访问策略更改为“ Blob”或“容器”来解决此问题,但这不能解决问题。 Running task on local celery worker completes without error with all access levels.
在所有访问级别下,本地celery worker上的运行任务都可以正确完成。 I have made sure the container exists and is spelled correctly.
我确保该容器存在且拼写正确。
Code to upload blob: 上传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)
When I attempt to upload through the container I get the following error message: 当我尝试通过容器上传时,收到以下错误消息:
AzureException('The specified resource does not exist. ErrorCode: ResourceNotFound\\n AzureException('指定的资源不存在。错误代码:ResourceNotFound \\ n
The "Put" requests have two differences: “放置”请求有两个区别:
Local: 'User-Agent': 'Azure-Storage/1.4.0-1.5.0 (Python CPython 3.7.3; Windows 10)' 本地:'User-Agent':'Azure-Storage / 1.4.0-1.5.0(Python CPython 3.7.3; Windows 10)
Container: 'User-Agent': 'Azure-Storage/1.4.0-1.5.0 (Python CPython 3.6.8; Linux 4.14.111-boot2docker)' 容器:'User-Agent':'Azure-Storage / 1.4.0-1.5.0(Python CPython 3.6.8; Linux 4.14.111-boot2docker)'
Also, when running locally, the "Authorization" header is generated, while when running from the container this header is missing. 同样,在本地运行时,会生成“授权”标头,而从容器运行时,会丢失此标头。 Any help would be greatly appreciated.
任何帮助将不胜感激。
Traceback: 追溯:
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>
Per my experience, there are two possible mistakes in your script. 根据我的经验,您的脚本中可能存在两个错误。
If the container container_name
does not exist in your storage account, so you need to call create_container
first before create_blob_from_text
. 如果您的存储帐户中不存在容器
container_name
,那么您需要在create_blob_from_text
之前先调用create_container
。 If it exists, create_container
function will not make any negative consequence for your work. 如果存在,
create_container
函数不会对您的工作产生任何负面影响。
block_blob_service.create_container('container_name') block_blob_service.create_blob_from_text('container_name', directory_main +
filename, demo_json) 文件名,demo_json)
Please refer to the offical document Naming and Referencing Containers, Blobs, and Metadata
, if you want to set some virtual directories for your blob, the correct way is to use /
not \\
. 请参考官方文档
Naming and Referencing Containers, Blobs, and Metadata
,如果要为Naming and Referencing Containers, Blobs, and Metadata
设置一些虚拟目录,正确的方法是使用/
not \\
。 So as the code below. 因此,如下所示。
directory_main = demo_data['username'] filename = '/demographics.json' # not '\\demographics.json'
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.