python - 如何在 Azure Blob 中上传大字符串?
问题描述
现在我正试图弄清楚如何使用 Azure,现在我在将我的数据存储在存储帐户中时遇到了一个问题。我有三个字符串,并希望将它们中的每一个存储在一个单独的 blob 中。对于前两个,我的代码工作正常,但第三个导致一些重试并以超时结束。我的代码在 Azure 函数中运行。
这是一个最小的例子:
from azure.storage.blob import BlobClient
blob_client = BlobClient.from_connection_string(
conn_str. = '<STORAGE_ACCOUNT_CONNECTION_STRING>',
container_name = '<CONTAINER_NAME>',
blob_name. = '<NAME_OF_BLOB>',
)
dic_blob_props = blob_client.upload_blob(
data = '<INFORMATION_THAT_SHOULD_GO_TO_THE_BLOB>',
blob_type = "BlockBlob",
overwrite = True,
)
前两个字符串一切正常,但第三个失败。字符串具有以下长度:
len(s_1) = 1246209
len(s_2) = 8794086
len(s_3) = 24518001
很可能是因为第三个字符串太长了,但一定有办法保存它,对吧?我已经尝试在.upload_blob
方法中设置超时时间 by timeout=600
,但这根本没有改变结果,也没有改变直到重新尝试写入的时间。
错误是:
Exception: ServiceResponseError: ('Connection aborted.', timeout('The write operation timed out'))
如果您对此问题有任何想法,请告诉我:-)
解决方案
在我这边,我没有问题。你可以看看我的代码:
__init__.py
import logging
import azure.functions as func
def main(req: func.HttpRequest,outputblob: func.Out[func.InputStream],) -> func.HttpResponse:
logging.info('This code is to upload a string to a blob.')
s_3 = "x"*24518001
outputblob.set(s_3)
return func.HttpResponse(
"The string already been uploaded to a blob.",
status_code=200
)
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "{test}",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"name": "outputblob",
"type": "blob",
"path": "test1/{test}.txt",
"connection": "str",
"direction": "out"
}
]
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "python",
"str":"DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx==;EndpointSuffix=core.windows.net"
}
}
然后我点击端点http://localhost:7071/api/bowman
,它将字符串上传到 blob 并且没有超时错误:
所以,我认为问题与您使用的方法有关。
推荐阅读
- ruby-on-rails - 设计会话链接
- r - 对于每一行,找到与特定字符串匹配的单元格并返回列名的最后一个字符
- c++ - 在 std::unordered_map 中找到一个值
- javascript - 使用 nodemailer 的联系表格不起作用
- docker - Meteor 2.2 项目的 Dockerfile
- git - 如果工作副本中的特定文件夹与存储库相同,如何使用 git diff 返回 0,如果它们不同则返回 1
- linux - *nix 主机的 sssd.conf ldap_user_search_base 多个 ous
- python - 如果它通过一个或多个 if 语句,我如何执行相同的语句?
- python - Python将循环中的数据附加到数据框中
- amazon-web-services - AWS Pre-Signed Post URL 突然停止工作