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

erroneous kwargs silently accepted by Client class #264

Open
MuellerSeb opened this issue Apr 21, 2021 · 3 comments
Open

erroneous kwargs silently accepted by Client class #264

MuellerSeb opened this issue Apr 21, 2021 · 3 comments

Comments

@MuellerSeb
Copy link

MuellerSeb commented Apr 21, 2021

The following fails

oc = owncloud.Client.from_public_link("<nc-url>/s/<public-token>", password="<pw>")
oc.mkdir("test")

with

HTTPResponseError                         Traceback (most recent call last)
<ipython-input-4-4007f7387f97> in <module>
----> 1 cl.mkdir("test")

/usr/local/lib/python3.6/dist-packages/owncloud/owncloud.py in mkdir(self, path)
    700         if not path.endswith('/'):
    701             path += '/'
--> 702         return self._make_dav_request('MKCOL', path)
    703 
    704     def delete(self, path):

/usr/local/lib/python3.6/dist-packages/owncloud/owncloud.py in _make_dav_request(self, method, path, **kwargs)
   1813         if res.status_code in [204, 201]:
   1814             return True
-> 1815         raise HTTPResponseError(res)
   1816 
   1817     def _parse_dav_response(self, res):

HTTPResponseError: HTTP error: 401

The following is working:

oc = owncloud.Client("<nc-url>")
oc.anon_login("<public-token>", "<pw>")
oc.mkdir("test")
@MuellerSeb
Copy link
Author

MuellerSeb commented Apr 21, 2021

I am just dumb. Needed to use folder_password instead of password:

oc = owncloud.Client.from_public_link("<nc-url>/s/<public-token>", folder_password="<pw>")
oc.mkdir("test")

is working fine.

Maybe this could just be a hint, that it silently accepted password which could be confusing.
This could be adjusted by checking the passed kwargs in

self._debug = kwargs.get('debug', False)

Instead of:

        self._debug = kwargs.get('debug', False)
        self._verify_certs = kwargs.get('verify_certs', True)
        self._dav_endpoint_version = kwargs.get('dav_endpoint_version', True)

One could use the following:

        self._debug = kwargs.pop('debug', False)
        self._verify_certs = kwargs.pop('verify_certs', True)
        self._dav_endpoint_version = kwargs.pop('dav_endpoint_version', True)
        if kwargs:
            print("unknown kwargs: {}".format(kwargs))

Or even raise a ValueError.

@MuellerSeb MuellerSeb changed the title NextCloud access from public link not working erroneous kwargs silently accepted by Client class Apr 21, 2021
@MuellerSeb
Copy link
Author

Or I am not so dumb after all.

The example in https://github.com/owncloud/pyocclient/blob/master/docs/source/README.rst shows the wrong usage of password, that was copied by me:

Example for downloading a file from a public shared folder with password:

import owncloud

public_link = 'http://domain.tld/owncloud/A1B2C3D4'
folder_password = 'secret'

oc = owncloud.Client.from_public_link(public_link, password=folder_password)
oc.get_file('/sharedfile.zip', 'download/destination/sharedfile.zip')

This should use folder_password=folder_password.

So we have both: A wrong documentation and a silent acceptance of wrong kwargs which will confuse users (like me).

@MuellerSeb
Copy link
Author

Documentation issue solved with #268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant