cloud-py-api/nc_py_api

Nextcloud.files.makedirs not working on Windwos

Closed this issue · 1 comments

Wuli6 commented

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

Indeed a bug, on Windows os.path.join(_path, i) will join paths with "\" instead of "/" which leads to this situation.

Thank you for reporting and proposing a correct fix, much appreciated.