Login and more operations using python

i have setup nextcloud locally in ubuntu using snap install nextcloud its working fine, now i want to login using python i have tried some libraries like

from nextcloud import NextCloud
nxc = NextCloud(
        endpoint="http://localhost/",
        user=username,
        password=password,
        json_output=True,
    )
nxc.login()

but its not return eny thing or error, next this is

import owncloud
oc = owncloud.Client('http://localhost/index.php/login')
oc.login(username, password)

giving error

raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /index.php/login/ocs/v1.php/cloud/capabilities (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb4e263a490>: Failed to establish a new connection: [Errno 111] Connection refused'))

kindly tell me its solution

In your first one, what result are you expecting? You’re just logging in. You have to trigger an operation after logging in I imagine to get anything.

What libraries are you using? (I can kind of guess, but your making us do more work than is necessary to help you hah).

You can/should check your Nextcloud logs if you want to get additional context about login failures.

I suggest you search the forum. There are relevant posts.

1 Like

i am using pip install nextcloud-api-wrapper

As Author of NextcloudPythonFramework I will be glad to answer of any questions related to Nextcloud and Python here or on GitHub.

2 Likes

how to verify that user sucessfully loggedin using python and without perform any operation???

Check return code from login request?

In nc_py_api I did not add possibility to do so, but if there will be strong argumented request for this I can add it in next upcoming version.

As a workaround I can suggest updating capabilities variable, as in most cases it will be updated after login anyway and cached, so reading it manually what will trigger it caching and will not impact performance in any way.

    nc = nc_py_api.Nextcloud(
        nc_auth_user="admin",
        nc_auth_pass="admin",
        nextcloud_url="http://stable27.local"
    )
    try:
        nc.update_server_info()
    except nc_py_api.NextcloudException as e:
        print(e)  # will be 401 in case of Auth error
1 Like