我正在使用下面的azure函数,它以http触发器作为输入。
import logging
import azure.functions as func
from . import test
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
strng = req.params.get('strng')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.sum = {test.testfunc(strng)}")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)下面是我在test.py中导入的init.py文件。
import json
import pandas as pd
from pandas import DataFrame
from azure.storage.blob import AppendBlobService
from datetime import datetime
def testfunc(strng):
# return strng
API = json.loads(strng)
test = pd.json_normalize(parse, record_path='Vol', meta=['studyDate'])
df = pd.DataFrame(test)
df["x"] = df["Vol"] * 2
df["y"] = df["Vol"] * 50
df1 = df[['Date', 'x', 'y']]
df2 = df1.to_json(orient='records')
append_blob_service = AppendBlobService(account_name='actname',
account_key='key')
date = datetime.now()
blobname = f"test_cal{date}.json"
append_blob_service.create_blob('container', blobname, if_none_match="*")
append_blob_service.append_blob_from_text('container', blobname, text=df2)
return df2当我在py魅力和databricks中运行它时,上面的函数就能工作了。但是当我通过可视化演播室代码运行Azure函数时,我会得到以下错误。
Exception: ImportError: cannot import name 'AppendBlobService' from 'azure.storage.blob'我在下面已经试过了,但仍然得到了同样的错误。
pip install azure-storage --upgrade
pip install azure-storage-blob请为错误提供帮助。
还有其他方法可以将df2变量保存到Azure存储中吗?
谢谢。
发布于 2022-06-30 06:00:30
当前版本库包含blobserviceclient而不是块块服务。对我来说,使用2.1.0版本可以解决这个问题:
pip install azure-storage-blob==2.1.0发布于 2022-06-30 04:16:17
根据文档的说法,
如果找不到模块(例如,
azure-storage-blob),如果找到ModuleNotFoundError.,就会抛出这个ModuleNotFoundError.,在加载模块或它的一些文件时可能会出现问题。在这种情况下,Python会抛出一个ImportError。
python设置为环境变量FUNCTIONS_WORKER_RUNTIME或azure.core添加到requirements.txt文件中。引用了:
https://stackoverflow.com/questions/72809831
复制相似问题