Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextcloud.files.makedirs not working on Windwos #280

Open
Wuli6 opened this issue Aug 1, 2024 · 1 comment
Open

Nextcloud.files.makedirs not working on Windwos #280

Wuli6 opened this issue Aug 1, 2024 · 1 comment
Labels
bug Something isn't working fixed in upcoming release fix will arrive with next release

Comments

@Wuli6
Copy link

Wuli6 commented Aug 1, 2024

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

@bigcat88 bigcat88 added the bug Something isn't working label Aug 1, 2024
@bigcat88
Copy link
Contributor

bigcat88 commented Aug 1, 2024

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.

bigcat88 added a commit that referenced this issue Aug 1, 2024
Reference: #280

Signed-off-by: Alexander Piskun <[email protected]>
@bigcat88 bigcat88 added the fixed in upcoming release fix will arrive with next release label Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in upcoming release fix will arrive with next release
Projects
None yet
Development

No branches or pull requests

2 participants