Error 401 when trying to connect stardog cloud (free)

import stardog
from pathlib import Path

# specify our endpoint, username, and password
# default values are provided, be sure to change if necessary
conn_details = {
    'endpoint': 'https://sd-<XXX>106.stardog.cloud:5820',
    'username': '<MAIL>',
    'password': '<SSO PASS>'
}

with stardog.Admin(**conn_details) as admin:
  db = admin.new_database('db')

  with stardog.Connection('db', **conn_details) as conn:
    conn.begin()
    conn.add(stardog.content.File('sample.ttl'))
    conn.commit()
    results = conn.select('select * { ?a ?p ?o }')

  db.drop()

Return>

Traceback (most recent call last):
  File "/home/kali/Desktop/Stardog/python-client/create_db.py", line 12, in <module>
    with stardog.Admin(**conn_details) as admin:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/Desktop/Stardog/python-client/env/lib/python3.11/site-packages/stardog/admin.py", line 53, in __init__
    self.alive()
  File "/home/kali/Desktop/Stardog/python-client/env/lib/python3.11/site-packages/stardog/admin.py", line 65, in alive
    r = self.client.get("/admin/alive")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/Desktop/Stardog/python-client/env/lib/python3.11/site-packages/stardog/http/client.py", line 59, in get
    return self.__wrap(self.session.get(self.url + path, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/Desktop/Stardog/python-client/env/lib/python3.11/site-packages/stardog/http/client.py", line 75, in __wrap
    raise exceptions.StardogException(
stardog.exceptions.StardogException: [401] : 

The endpoint and the credentials are correct.

1 Like

Hi,

I think instead of using your SSO password, you need to use the password specific to your endpoint. You can set this password by going into Studio, go to the Security tab and select your user. Select the menu in the upper right corner and select "Change Password". This should allow you to set a password for your user on this endpoint.
Screenshot 2024-03-06 at 07.25.45

You can then use the password to connect to our endpoint in your python script.

Best regards,

Lars

Hi Lars, thank you for your response. After making the changes, everything is working correctly. Thank you.

I don’t see this option while using stardog free

Hello Akshay,

What is it that you are trying to do? If you want to access your Stardog Cloud Free endpoint through the API, then you need to create a username and password for programmatic access. See Accessing API Endpoint | Stardog Documentation Latest for more details. In order to create an API user and/or change the user’s password, the easiest approach is to use Stardog Studio.

Regards,

Paul Place

Hi Paul,

Appreciate your quick response. I was trying to connect to the endpoint using the pystardog python package. I was trying to connect using my details on the portal.

I managed to connect once I updated the password in studio.

Thank you,

AK