我正在Azure HTTP函数中直接调用第三方API。我希望将json响应保存到Azure Blob存储容器内的文件中。当我尝试调试Azure函数时,我生成的以下代码(基于Microsoft文档)挂起。当命中Azure函数URL终结点时,上述进程挂起并且永远无法完成任务。我的代码是否缺少某些内容?
import os
import logging
import requests
import azure.functions as func
from azure.storage.blob import BlobServiceClient,BlobClient
import json
def main(req: func.HttpRequest) -> func.HttpResponse:
connection_string = os.getenv([Azure Blob Storage Connection String])
file_name = 'SurveySchema.json'
blob = BlobClient.from_connection_string(conn_str=connection_string, container_name=[container name], blob_name=[name of json file])
request = requests.get('[The API endpoint that returns json response body]')
try:
logging.info(request.text)
blob.set(str(request.text))
except ValueError as err:
logging.info("Error getting data from endpoint, %s", err)
return func.HttpResponse('Request processed successfully.', status_code=200)
1条答案
按热度按时间5n0oy7gb1#
这是一个简单的修复!我不得不使用“upload_blob”方法从Blob客户端库