Skip to content

Nextcloud.files.makedirs not working on Windwos #280

@Wuli6

Description

@Wuli6

Describe the bug

In the makedirs function the path is created with help of os functions. On my Windows machine i get:
NextcloudException(status_code, reason=codes(status_code).phrase, info=info) nc_py_api._exceptions.NextcloudException: [400] Bad Request <request: MKCOL https://nextcloud.XXX.com/remote.php/dav/files/Testuser/Folder%5CSubfolder

After a short debug i found the error in the line 177 os.path.join(_path, i).
The os function inserts a \ instead of /.

My simple fix is in nc_py_api/files/files.py Line 177:
replace:
_path = os.path.join(_path, i)
with:
_path = f"{_path}/{i}"

Steps/Code to Reproduce

import nc_py_api

if __name__ == "__main__":
    nc = nc_py_api.Nextcloud(nextcloud_url="your.nextcloud.com", nc_auth_user="Testuser", nc_auth_pass="Password")
    nc.files.makedirs(path="/Folder/Subfolder", exist_ok=True)
    exit(0)

Expected Results

It creats folders if they dont exist

Actual Results

Throws Exception

Setup configuration

nc-py-api==0.15.0
nextcloud = 29.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed in upcoming releasefix will arrive with next release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions