python-icat in a jupyter notebook

9 views
Skip to first unread message

stuartp...@gmail.com

unread,
Sep 17, 2021, 9:18:36 AM9/17/21
to icatgroup
Hi,

Does anyone have experience with using python-icat from a jupyter notebook? I would like to provide an icat.cfg file for users of our STFC JupyterHub system. The config file would configure the ISIS and Diamond ICAT URLs and authenticators.

Python-ICAT raises an exception when I try to create the configuration object*. I think it is trying to read the commandline options and finding the Jupyter script's options not python-icat options. Is there a way to create a config object from a config file without also reading the commandline options?

Any help would be much appreciated.
Thanks,
Stuart

*
#------------------------
import icat.config

config = icat.config.Config()
client, conf = config.getconfig()
#--------------------------
usage: ipykernel_launcher.py [-h] [-c CONFIGFILE] [-s SECTION] [-w URL]
                                   [--idsurl IDSURL] [--no-check-certificate] 
                                   [--http-proxy HTTP_PROXY] 
                                   [--https-proxy HTTPS_PROXY] [--no-proxy NO_PROXY]
                                   [-a AUTH] [-u USERNAME] [-P] [-p PASSWORD] 
ipykernel_launcher.py: error: unrecognized arguments: -f /home/jovyan/.local/share/jupyter/runtime/kernel-1417027b-39c4-4c47-ab42-31ab16a2d549.json
An exception has occurred, use %tb to see the full traceback. SystemExit: 2

Rolf Krahl

unread,
Sep 17, 2021, 10:41:51 AM9/17/21
to icat...@googlegroups.com
Hi,

Am Freitag, 17. September 2021, 15:18:36 CEST schrieb stuartp...@gmail.com:
>
> Python-ICAT raises an exception when I try to create the configuration
> object*. I think it is trying to read the commandline options and finding
> the Jupyter script's options not python-icat options.

Yes, that seem to be the issue here. The icat.config module takes
configuration from command line arguments, environment variables, and
configuration files. The command line arguments are taken from
sys.argv by default. In your case, these seem to be the command line
arguments from the Jupyter script, which do not make much sense to
icat.config.

> Is there a way to create a config object from a config file without
> also reading the commandline options?

Yes, this default can be overridden using the 'args' keyword argument
in Config().

> #------------------------
> import icat.config
>
> config = icat.config.Config()
> client, conf = config.getconfig()
> #--------------------------

You may use the following to pretend not having any command line
arguments:

| config = icat.config.Config(args=())
| client, conf = config.getconfig()

Or you may use that to inject some configuration from your script:

E.g. set the config section to read:

| cfgsection = 'isis'
| config = icat.config.Config(args=('-s', cfgsection))
| client, conf = config.getconfig()

or set username and password:

| cfgsection = 'isis'
| user = 'jdoe'
| pw = 'secret'
| config = icat.config.Config(args=('-s', cfgsection, '-u', user, '-p', pw))
| client, conf = config.getconfig()

Best regards,
Rolf

--
Rolf Krahl <rolf....@helmholtz-berlin.de>
Helmholtz-Zentrum Berlin für Materialien und Energie (HZB)
Albert-Einstein-Str. 15, 12489 Berlin
Tel.: +49 30 8062 12122

stuartp...@gmail.com

unread,
Sep 17, 2021, 12:21:35 PM9/17/21
to icatgroup
>  Yes, this default can be overridden using the 'args' keyword argument
in Config().

Thanks. This fixed it.

Stuart

Reply all
Reply to author
Forward
0 new messages