login via web works, but fails in python

67 views
Skip to first unread message

a.m....@gmail.com

unread,
Aug 30, 2022, 8:55:08 AM8/30/22
to xnat_discussion
When I login to my (NRG-style) XNAT via the web interface, my username and password are accepted.

But when I use https://xnat.readthedocs.io I get (with my credentials in ~/.netrc):

>>> import xnat
>>> session=xnat.connect('https://rng-xnat.ecloud.vumc.nl', verify=False)
[WARNING] Verify is disabled, this will NOT verify the certificate of SSL connections!
[WARNING] Warnings about invalid certificates will be HIDDEN to avoid spam, but this
[WARNING] means that your connection can be potentially unsafe!
[ERROR] Could not determine if login was successful!
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 557, in connect
   logged_in_user = check_auth_guest(requests_session, server=server, logger=logger)
 File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 79, in check_auth_guest
   raise exceptions.XNATAuthError(message)
xnat.exceptions.XNATAuthError: Could not determine if login was successful!

and (without ~/.netrc)

>>> session=xnat.connect('http://rng-xnat.ecloud.vumc.nl',verify=False,user='amwink')
[WARNING] Verify is disabled, this will NOT verify the certificate of SSL connections!
[WARNING] Warnings about invalid certificates will be HIDDEN to avoid spam, but this
[WARNING] means that your connection can be potentially unsafe!
Please enter the password for user 'amwink':
[WARNING] Detected a redirect from http://rng-xnat.ecloud.vumc.nl to https://rng-xnat.ecloud.vumc.nl/, using https://rng-xnat.ecloud.vumc.nl/ from now on
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 579, in connect
   build_model(xnat_session, extension_types=extension_types, connection_id=connection_id)
 File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 351, in build_model
   build_function(parser, xnat_session, extension_types=extension_types)
 File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 219, in parse_schemas_17
   parser.parse_schema_uri(xnat_session=xnat_session,
 File "/usr/local/lib/python3.8/dist-packages/xnat/convert_xsd.py", line 1005, in parse_schema_uri
   return self.parse_schema_xmlstring(data, schema_uri=schema_uri)
 File "/usr/local/lib/python3.8/dist-packages/xnat/convert_xsd.py", line 978, in parse_schema_xmlstring
   self.parse(root, toplevel=True)
 File "/usr/local/lib/python3.8/dist-packages/xnat/convert_xsd.py", line 1103, in parse
   self.PARSERS[element.tag](self, element)
 File "/usr/local/lib/python3.8/dist-packages/xnat/convert_xsd.py", line 1272, in _parse_schema
   self.target_namespace_prefix = self.namespace_prefixes[self.target_namespace] + ':'
KeyError: 'http://nrg.wustl.edu/xdat'

I used to have problems with specific certificates and need to use the "verify = False" setting to get in, but that has worked fine. This seems to be another problem?


a.m....@gmail.com

unread,
Aug 30, 2022, 9:14:23 AM8/30/22
to xnat_discussion
Two things I should have added:
    1. I am using XNAT 1.8.4.1 --I think that's the highest version compatible with my existing postgres-- and had to switch TomCat to version 9-jre8-alpine
        (XNAT version is set in xnat-docker-compose/docker-compose.yml and TomCat in xnat-docker-compose/xnat/Dockerfile)
    2. The error is not because of bad credentials --I did have that error once for typing too fast:
    Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 528, in connect
       jsession_token = _create_jsession(requests_session,
     File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 289, in _create_jsession
       raise exceptions.XNATLoginFailedError('Encountered a problem logging in: {}'.format(message))
    xnat.exceptions.XNATLoginFailedError: Encountered a problem logging in: Bad credentials


a.m....@gmail.com

unread,
Aug 30, 2022, 10:40:11 AM8/30/22
to xnat_discussion
I have upgraded from version 4.1 to 4.2 of https://xnat.readthedocs.io, which makes it possible to login by typing the user name / user name and password:
>>> session=xnat.connect('http://rng-xnat.ecloud.vumc.nl:80',verify=False,user='amwink')
[WARNING] Verify is disabled, this will NOT verify the certificate of SSL connections!
[WARNING] Warnings about invalid certificates will be HIDDEN to avoid spam, but this
[WARNING] means that your connection can be potentially unsafe!
Please enter the password for user 'amwink':
[WARNING] Detected a redirect from http://rng-xnat.ecloud.vumc.nl:80 to https://rng-xnat.ecloud.vumc.nl/, using https://rng-xnat.ecloud.vumc.nl/ from now on

However: with my credentials in ~/.netrc I still get the same error (slightly different line numbers):
>>> session=xnat.connect('http://rng-xnat.ecloud.vumc.nl:80',verify=False)                                      

[WARNING] Verify is disabled, this will NOT verify the certificate of SSL connections!
[WARNING] Warnings about invalid certificates will be HIDDEN to avoid spam, but this
[WARNING] means that your connection can be potentially unsafe!
[ERROR] Could not determine if login was successful!
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 568, in connect
   logged_in_user = check_auth_guest(requests_session, server=server, logger=logger)
 File "/usr/local/lib/python3.8/dist-packages/xnat/__init__.py", line 79, in check_auth_guest
   raise exceptions.XNATAuthError(message)
xnat.exceptions.XNATAuthError: Could not determine if login was successful!

This is in my ~/.netrc, I am quite sure I have followed the instructions to the letter:
$ cat ~/.netrc
machine http://rng-xnat.ecloud.vumc.nl
   user amwink
   password SOMECODE

Could the syntax for the .netrc file have changed?

John Flavin

unread,
Aug 30, 2022, 10:52:26 AM8/30/22
to xnat_di...@googlegroups.com
In the last example, you used http://rng-xnat.ecloud.vumc.nl:80 as the url when connecting but the netrc file only has an entry for http://rng-xnat.ecloud.vumc.nl without the :80 port at the end.

I suspect that port is the reason it cannot find your credentials in the file, and if you remove the :80 when connecting it will work.

John Flavin
Backend Team Lead
He/Him



--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/e63ba36e-0587-4a38-b97a-ea6431bc7576n%40googlegroups.com.

a.m....@gmail.com

unread,
Aug 31, 2022, 3:51:29 AM8/31/22
to xnat_discussion
Thanks very much, John!

The combination that works now is that in the .netrc file it just says "machine rng-xnat.ecloud.vumc.nl" (so no port, no protocol) and on the command line I use https:// but no port number.

So I guess the more a-specific the .netrc file is, the more situations are compatible with the settings? That would make sense.
Reply all
Reply to author
Forward
0 new messages