import logging
from azure.cosmos import exceptions, CosmosClient, PartitionKey
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
endpoint = "https://xxxx.documents.azure.com:443/"
key = '******=='
client = CosmosClient(endpoint, key)
database_name = 'mydb'
database = client.create_database_if_not_exists(id=database_name)
container_name= 'mycoll'
container = database.create_container_if_not_exists(id=container_name,partition_key=PartitionKey(path="/name"),
offer_throughput=400)
query = 'SELECT * FROM c WHERE c.name = "Anupam"'
items = list(container.query_items(query=query, enable_cross_partition_query=True))
print(items)
return func.HttpResponse(items, status_code=200)
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
)
{[2021-02-10T06:34:16.248Z] Worker failed to function id 4af477f8-eff0-4937-b87f-98f7828d95ec.
[2021-02-10T06:34:16.250Z] Result: Failure
Exception: AttributeError: module 'azure.functions' has no attribute 'In'
Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.8/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 271, in _handle__function_load_request
func = loader.load_function(
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.8/WINDOWS/X64\azure_functions_worker\utils\wrappers.py", line 32, in call
return func(*args, **kwargs)
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.8/WINDOWS/X64\azure_functions_worker\loader.py", line 76, in load_function
mod = importlib.import_module(fullmodname)
File "C:\Users\dell\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\Visual Studio\Projects\Functions1\SBTopicTrigger1\__init__.py", line 5, in <module>
def main(message: func.ServiceBusMessage, inputdocument: func.In[func.Document], outputSbMsg:func.ServiceBusMessage):
.}
下面是我的function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
有什么想法可以摆脱这个“exception:attributeError:module'azure.functions'没有属性'in'”错误吗?
RTM
function.json
缺少Cosmos输入绑定,例如
{
"type": "cosmosDB",
"name": "todoitems",
"databaseName": "ToDoItems",
"collectionName": "Items",
"connectionStringSetting": "CosmosDBConnection",
"direction": "in",
"Id": "{Query.id}",
"PartitionKey": "{Query.partitionKeyValue}"
}
func.documentlist
而不是func.in
import logging
import azure.functions as func
def main(req: func.HttpRequest, todoitems: func.DocumentList) -> str:
if not todoitems:
logging.warning("ToDo item not found")
else:
logging.info("Found ToDo item, Description=%s", todoitems[0]['description'])
return 'OK'
如官方文档中所述,Cosmos Db SQL API支持聚合函数。然而,我找不到任何对项的多级文档结构执行聚合的良好查询示例。这是我的Cosmos DB容器项的结构。我正在使用SQL API } 我想得到发票明细的总和。使用SQL查询的lineTotal。非常感谢您的回答
我正在使用Azure函数V1 c#。我有一个时间触发的azure函数,它每秒都在检查我的数据库中的一些数据。如果找到了数据,我想对它执行一些操作。此操作可能需要30秒到5分钟的时间,具体取决于其上发生的操作。 > 当我的时间触发函数获取数据并开始对其执行操作时。在第一个操作完成之前,时间触发的函数不会再次执行。因此,即使时间触发函数被安排为每秒执行一次,如果上一次迭代中的操作花费了 30 秒,则在
在将我的Azure Functions项目迁移到.NET5之后,它已经开始在一个奇怪的包装类中包装我的响应。 例如,考虑以下endpoint: 之前,它会返回: 但现在,它又回来了: 我知道这一定是因为它只是尝试序列化对象结果,但我找不到任何文档说明这在.NET5中应该如何工作。 我的主要功能目前看起来是这样的: 我的项目位于这里,以防有人感兴趣:https://github.com/sponso
我确信已经有人这样做了,但是我还没有找到任何关于Microsoft JWT实现的留档。Microsoft为其JWT库提供的官方留档基本上是一个空页面,请参阅: https://docs.microsoft.com/en-us/dotnet/framework/security/json-web-token-handler-api-reference 因此,以下是我(我相信还有许多其他人)想要实现的
在我的Azure云帐户中,我可以访问多个订阅,每个订阅中有多个资源组。每个资源组又可以具有跨不同位置的多个功能。 我可以访问给定资源组的函数,如下所示: