Download from nextcloud with enabled 2FA file with python

I would like to download files from nextcloud with a Python script. I have 2-factor authentication enabled and I can’t really find good information on how to use the library requests or sth similar do achieve what I want.

I tried to use pyocclient https://github.com/owncloud/pyocclient just to see if I could connect like this:

import owncloud

oc = owncloud.Client(‘https://mynextcloudinstance’)
oc.login(‘myuser’, ‘mypass’)
oc.mkdir(‘new_dir’)

This throws an owncloud.owncloud.HTTPResponseError: HTTP error: 401. error

Is there a better library or a better way to do this? Or is that due to 2-factor authentication and if so, is there a way to circumvent that? Or how could I achieve that with the webdav protocol?

Thanks for any help, very much appreciated!

You can create an app password for your python app in settings -> security.

1 Like

Thank you @mmccarn. Creating the password worked! I could also manage to use python’s request library connecting it to the webdav API. Thanks again