Os.mkdir is not able to create new folder in Space
I have an API that is working smoothly on my local. Then, I tried to deploy my API with Space but I am always having a permission issue as belowFile "/api/sabiduria_tool_api/services/service_sabiduria_tool.py", line 35, in save_files
    mkdir(self.data_store_path)
PermissionError: [Errno 13] Permission denied: '/api/sabiduria_tool_api/data/'Here is the method that is failingasync def save_files(self) -> None:
    if isdir(self.data_store_path):
        old_files = self.get_files()
        for o_file in old_files:
            remove(f"{self.data_store_path}{o_file}")
    else:
        mkdir(self.data_store_path)
    for file in self.files:
        with open(f"{self.data_store_path}{file.filename}", "wb") as destination:
            copyfileobj(file.file, destination)Here is my docker fileFROM python:3.9.7

COPY ./requirements.txt /api/requirements.txt
COPY ./sabiduria_tool_api /api/sabiduria_tool_api

WORKDIR /api

RUN pip install --upgrade pip
RUN pip install -r requirements.txt

CMD ["uvicorn", "sabiduria_tool_api.main:app", "--host", "0.0.0.0", "--port", "7860"]Is there a way that I can create a folder?
2023-08-16T09:51:39Z
Hello@serdarakyol,Issue is your space is running with an unprivileged user while by default during a docker build commands are run as root.To prevent this issue you need to copy your resources specifying the owner.FROM python:3.9.7

# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Switch to the "user" user
USER user

COPY --chown=user ./requirements.txt /api/requirements.txt
COPY --chown=user ./sabiduria_tool_api /api/sabiduria_tool_api

WORKDIR /api

RUN pip install --upgrade pip
RUN pip install -r requirements.txt

CMD ["uvicorn", "sabiduria_tool_api.main:app", "--host", "0.0.0.0", "--port", "7860"]You’ll find more info regarding permissions issues in thedocumentation
2023-08-16T13:37:27Z
let us know if this solves your issue@serdarakyol!
2024-04-19T10:25:06Z
I have this in Dockerfile:FROM python:3.9.12ENV PYTHONDONTWRITEBYTECODE 1ENV PYTHONUNBUFFERED 1WORKDIR /appCOPY . /appRUN apt-get update && apt-get install -y \libgl1-mesa-glx \&& rm -rf /var/lib/apt/lists/*RUN pip install --no-cache-dir flask tensorflow jsonifyRUN pip install --no-cache-dir gunicornEXPOSE 5000CMD [“gunicorn”, “–workers”, “2”, “–timeout”, “180”, “–bind”, “0.0.0.0:5000”, “app:app”]I am getting permission error when my app.py runs, telling:…os.makedirs(temp_folder, exist_ok=True)File “/usr/local/lib/python3.9/os.py”, line 225, in makedirsmkdir(name, mode)PermissionError: [Errno 13] Permission denied: ‘temporary’[2024-04-19 06:57:15 +0000] [8] [INFO] Worker exiting (pid: 8)[2024-04-19 06:57:15 +0000] [1] [ERROR] Worker (pid:7) exited with code 3[2024-04-19 06:57:15 +0000] [1] [ERROR] Worker (pid:8) was sent SIGTERM![2024-04-19 06:57:15 +0000] [1] [ERROR] Shutting down: Master[2024-04-19 06:57:15 +0000] [1] [ERROR] Reason: Worker failed to boot.
2024-04-19T18:21:35Z
hi@i-darrshanplease make sure you the running user has permission, follow our guide herehuggingface.coDocker SpacesWe’re on a journey to advance and democratize artificial intelligence through open source and open science.
2024-04-24T23:48:55Z
I ran that, but got some errors. So I request to modify and provide the dockerfile script for me
2024-04-25T16:56:51Z
hi@i-darrshancould you please share a public Space ? We’d be happy to help you here
2024-04-28T02:37:12Z
hi@radames. I have made the  repository public. You can now access it at i-darrshan/defecto
2024-10-15T06:36:08Z
Hi@i-darrshan,I am facing this issueimage870×576 20.9 KBdocker file:image911×780 19.9 KBCan you share the dockerfile contents regarding permission to create folders and files