Using --sudo functionality in Python and JSON APIs
Posted: Wed Jul 18, 2018 10:55 pm
Hi team,
I have a few Python scripts that retrieve stuff from OMERO, some via the Python API and some via the JSON API. All works fine but now I would like to access that stuff as another user so I get their rendering settings and such. So I was looking to use something similar to the --sudo functionality in CLI.
With the Python API I connect via BlitzGateway where I don't see a sudo option. There probably is something since the various CLI commands do have a --sudo option, no?
With JSON API, I use a small section of code that originated with Will and/or Ola:
Is there a "sudo" option somewhere?
Thanks,
- Damir
I have a few Python scripts that retrieve stuff from OMERO, some via the Python API and some via the JSON API. All works fine but now I would like to access that stuff as another user so I get their rendering settings and such. So I was looking to use something similar to the --sudo functionality in CLI.
With the Python API I connect via BlitzGateway where I don't see a sudo option. There probably is something since the various CLI commands do have a --sudo option, no?
With JSON API, I use a small section of code that originated with Will and/or Ola:
- Code: Select all
def connect_to_omero(base_url: str, user: str, password: str):
session = requests.Session()
login_url = base_url + '/webclient/login/'
session.get(login_url)
token = session.cookies['csrftoken']
if (user == None):
user = input('OMERO Username (return for public repository): ')
if (password == None):
password = getpass.getpass('OMERO Password (return for public repository): ')
# Login with username, password and server
payload = {'username': user,
'password': password,
'server': 1,
'noredirect': 1,
'csrfmiddlewaretoken': token}
r = session.post(login_url, data=payload, headers=dict(Referer=login_url))
# Return session handle
return session
Is there a "sudo" option somewhere?
Thanks,
- Damir