Having Problems with error 401 in Azure Functions

  Kiến thức lập trình

I’m trying to use more than one function in my Azure Function, but while the first one created works normally (returns me a Status 200), the second one always returns a 401 error, it is a code that must accept one JSON and return another JSON. I’ve already enabled and disabled CORS, changed the AuthLevel to Anonymous, and among other things, but it always returns me this 401 error. I created a third test function, and it also returns the 401 error. Its code is nothing more than the “Hello World” of the Azure Function, there’s nothing special about it.

Has this ever happened to anyone? Do you know what it could be?

enter image description here

I don’t know if this is relevant, but when trying to run the second or third function locally, this error is returned to me. However, he cites the first code, which works:

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'.

I tried changing the permissions for Function, Anonymous and Admin and none of them worked. I also enabled CORS.

LEAVE A COMMENT