Getting Access Denied Error When Hitting API (Although, API is working fine when running on LocalHost via Django)

I used GPT4all to create a RAG Pipeline with the help of langchain. When I use API for other purposes, it works fine but when I Hit the RAG pipeline, It gives access denied error.

Error getting: Permission Error Root Cause: Unable to create model download directory in system profile. Access denied to 'C:\Windows\system32\config\systemprofile.cache'

Environment:- Python Version: 3.12 Operating System: Windows Key Packages: * langchain * gpt4all * pydantic

Full Error: {"error":"Error in Database Chain: Failed to create model download directory","traceback":"Traceback (most recent call last):\n File "C:\Python312\Lib\site-packages\gpt4all\gpt4all.py", line 323, in retrieve_model\n os.makedirs(DEFAULT_MODEL_DIRECTORY, exist_ok=True)\n File "", line 215, in makedirs\n File "", line 225, in makedirs\nPermissionError: [WinError 5] Access is denied: 'C:\\Windows\\system32\\config\\systemprofile\\.cache'\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "C:\inetpub\wwwroot\hashmove-ai\HMAI\Controllers\ConversationalAIv2_Controller.py", line 143, in post\n hmgpt_response = query_response(input_query, query_intent)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "C:\inetpub\wwwroot\hashmove-ai\HMAI_Business\ConversationalAIv2_Business.py", line 281, in query_response\n return response_functions.get(intent_response, irrelevant)(query)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "C:\inetpub\wwwroot\hashmove-ai\HMAI_Business\ConversationalAIv2_Business.py", line 251, in logistics\n chain = log_chain(load_llm(), vector_db(), memory(), log_prompt())\n ^^^^^^^^^^\n File "C:\inetpub\wwwroot\hashmove-ai\HMAI_Business\ConversationalAIv2_Business.py", line 90, in load_llm\n loaded_llm = GPT4All(\n ^^^^^^^^\n File "C:\Python312\Lib\site-packages\langchain_core\load\serializable.py", line 125, in init\n super().init(*args, **kwargs)\n File "C:\Python312\Lib\site-packages\pydantic\main.py", line 212, in init\n validated_self = self.pydantic_validator.validate_python(data, self_instance=self)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "C:\Python312\Lib\site-packages\pydantic\_internal\_decorators_v1.py", line 148, in _wrapper1\n return validator(values)\n ^^^^^^^^^^^^^^^^^\n File "C:\Python312\Lib\site-packages\langchain_core\utils\pydantic.py", line 208, in wrapper\n return func(cls, values)\n ^^^^^^^^^^^^^^^^^\n File "C:\Python312\Lib\site-packages\langchain_community\llms\gpt4all.py", line 145, in validate_environment\n values["client"] = GPT4AllModel(\n ^^^^^^^^^^^^^\n File "C:\Python312\Lib\site-packages\gpt4all\gpt4all.py", line 235, in init\n self.config: ConfigType = self.retrieve_model(model_name, model_path=model_path, allow_download=allow_download, verbose=verbose)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "C:\Python312\Lib\site-packages\gpt4all\gpt4all.py", line 325, in retrieve_model\n raise RuntimeError("Failed to create model download directory") from e\nRuntimeError: Failed to create model download directory\n"}

Tried giving manuall path to the cache:

os.environ["TIKTOKEN_CACHE_DIR"] = "embeddings-cache"

But didn't worked.

Note: I've deployed this on a server using IIS server.

I've deployed this on a server using IIS server

The error message is clear, it is an identity permission problem. What identity does your application access as? Anonymous identity or something else?

But based on the error message, it seems that your code related to some system driver folder permission. You can try to set admin permission in Application pool identity.

  1. Open the Application Pools node underneath the machine node. Select the application pool you want to change.
  2. Right click the application pool and select Advanced Settings.
  3. Select the Identity list item and click the ellipsis (the button with the three dots).
  4. Check Custom account and Set....
  5. Enter Enter the local administrator name and password. enter image description here
Back to Top