在 Azure Functions 中遇到错误 401 问题

问题描述 投票:0回答:1

我尝试在 Azure 函数中使用多个函数,但是虽然创建的第一个函数正常工作(返回状态 200),但第二个函数始终返回 401 错误,它是必须接受一个 JSON 的代码并返回另一个 JSON。我已经启用和禁用了 CORS,将 AuthLevel 更改为匿名,等等,但它总是返回这个 401 错误。我创建了第三个测试函数,它也返回 401 错误。它的代码无非就是Azure Function的“Hello World”,没有什么特别之处。

有人遇到过这种情况吗?你知道它可能是什么吗?

我不知道这是否相关,但是当尝试在本地运行第二个或第三个函数时,此错误会返回给我。然而,他引用了第一个代码,该代码有效:

Azure Functions Core Tools
Core Tools Version:       4.0.5530 Commit hash: N/A +c8883e7f3c06e2b424fbac033806c19d8d91418c (64-bit)
Function Runtime Version: 4.28.5.21962

[2024-04-11T11:24:55.902Z] Customer packages not in sys path.
[2024-04-11T11:24:56.807Z] Worker process started and initialized.

Functions:

        func-fortdevai: [GET,POST,PATCH,DELETE] http://localhost:7071//{*route}

        func-fortdevai-documents: [GET,POST,PATCH,DELETE] http://localhost:7071/ProcessDocuments

        func-test: [GET,POST] http://localhost:7071/func-test

For detailed output, run func with --verbose flag.
[2024-04-11T11:24:59.361Z] Executing 'Functions.func-fortdevai' (Reason='This function was programmatically called via the host APIs.', Id=6976b1cd-9fb1-4150-bbf3-5fd19ccba200)
[2024-04-11T11:24:59.409Z] Python HTTP trigger function processed a request.
[2024-04-11T11:24:59.484Z] Loading faiss with AVX2 support.
[2024-04-11T11:24:59.484Z] Loading faiss.
[2024-04-11T11:24:59.484Z] Could not load library with AVX2 support due to:
[2024-04-11T11:24:59.485Z] ModuleNotFoundError("No module named 'faiss.swigfaiss_avx2'")
[2024-04-11T11:24:59.500Z] Successfully loaded faiss.
[2024-04-11T11:24:59.764Z] Executed 'Functions.func-fortdevai' (Failed, Id=6976b1cd-9fb1-4150-bbf3-5fd19ccba200, Duration=421ms)
[2024-04-11T11:24:59.764Z] System.Private.CoreLib: Exception while executing function: Functions.func-fortdevai. System.Private.CoreLib: Result: Failure
[2024-04-11T11:24:59.764Z] Exception: TypeError: expected string or buffer
[2024-04-11T11:24:59.764Z] Stack:   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 495, in _handle__invocation_request
[2024-04-11T11:24:59.764Z]     call_result = await self._loop.run_in_executor(
[2024-04-11T11:24:59.764Z]   File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
[2024-04-11T11:24:59.764Z]     result = self.fn(*self.args, **self.kwargs)
[2024-04-11T11:24:59.764Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 768, in _run_sync_func
[2024-04-11T11:24:59.764Z]     return ExtensionManager.get_sync_invocation_wrapper(context,
[2024-04-11T11:24:59.764Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper
[2024-04-11T11:24:59.764Z]     result = function(**args)
[2024-04-11T11:24:59.764Z]   File "/home/artur/Área de Trabalho/teste_azure_3/func-fortdevai/__init__.py", line 13, in main
[2024-04-11T11:24:59.764Z]     result = get_risks(service_category, service_name, service_description)
[2024-04-11T11:24:59.764Z]   File "/home/artur/Área de Trabalho/teste_azure_3/func-fortdevai/risks.py", line 186, in get_risks
[2024-04-11T11:24:59.764Z]     results = extract_elements(db, service_category, service_name, service_description)
[2024-04-11T11:24:59.764Z]   File "/home/artur/Área de Trabalho/teste_azure_3/func-fortdevai/risks.py", line 134, in extract_elements
[2024-04-11T11:24:59.764Z]     chunks = db.similarity_search_with_score(description, k=3)
[2024-04-11T11:24:59.765Z]   File "/home/artur/Área de Trabalho/teste_azure_3/.venv/lib/python3.10/site-packages/langchain_community/vectorstores/faiss.py", line 402, in similarity_search_with_score
[2024-04-11T11:24:59.765Z]     embedding = self._embed_query(query)
[2024-04-11T11:24:59.765Z]   File "/home/artur/Área de Trabalho/teste_azure_3/.venv/lib/python3.10/site-packages/langchain_community/vectorstores/faiss.py", line 154, in _embed_query
[2024-04-11T11:24:59.765Z]     return self.embedding_function.embed_query(text)
[2024-04-11T11:24:59.765Z]   File "/home/artur/Área de Trabalho/teste_azure_3/.venv/lib/python3.10/site-packages/langchain_openai/embeddings/base.py", line 546, in embed_query
[2024-04-11T11:24:59.765Z]     return self.embed_documents([text])[0]
[2024-04-11T11:24:59.765Z]   File "/home/artur/Área de Trabalho/teste_azure_3/.venv/lib/python3.10/site-packages/langchain_openai/embeddings/base.py", line 517, in embed_documents
[2024-04-11T11:24:59.765Z]     return self._get_len_safe_embeddings(texts, engine=engine)
[2024-04-11T11:24:59.765Z]   File "/home/artur/Área de Trabalho/teste_azure_3/.venv/lib/python3.10/site-packages/langchain_openai/embeddings/base.py", line 310, in _get_len_safe_embeddings
[2024-04-11T11:24:59.765Z]     token = encoding.encode(
[2024-04-11T11:24:59.765Z]   File "/home/artur/Área de Trabalho/teste_azure_3/.venv/lib/python3.10/site-packages/tiktoken/core.py", line 116, in encode
[2024-04-11T11:24:59.765Z]     if match := _special_token_regex(disallowed_special).search(text):
[2024-04-11T11:24:59.765Z] .
[2024-04-11T11:25:01.727Z] Host lock lease acquired by instance ID '000000000000000000000000FB508126'.

我尝试更改功能、匿名和管理员的权限,但都不起作用。我还启用了 CORS。

python azure deployment azure-functions http-status-code-401
1个回答
0
投票

您可能正在尝试使用仅限第一个函数的功能密钥来验证其他函数。

在 Azure 门户中,如果您选择一个功能,然后从菜单中选择“功能键”,则会返回仅对该功能有效的键。

相反,在功能应用程序本身,从菜单中选择“应用程序键”,然后尝试使用应用程序键而不是功能键。应用程序密钥将可以访问应用程序中的所有功能。

© www.soinside.com 2019 - 2024. All rights reserved.