Trouble connecting to omero server with Python

I’m trying to connect to a demo OMERO server I’ve setup, but I can’t seem to connect with Python. I’ve tested both the web client and OMERO.Insight, and both are able to connect. The server is running Ubuntu 18.04 with the latest OMERO server/web installed via Docker. I’m following the documentation here.

from omero.gateway import BlitzGateway
from getpass import getpass

def connect(hostname, username, password):
    """
    Connect to an OMERO server
    :param hostname: Host name
    :param username: User
    :param password: Password
    :return: Connected BlitzGateway
    """
    conn = BlitzGateway(username, password,
                        host=hostname, secure=True)
    conn.connect()
    conn.c.enableKeepAlive(60)
    return conn

HOST = 'xx.xx.xx.xxx'
conn = connect(HOST, input("Username: "),
               getpass("OMERO Password: "))
print("Connected as {}".format(conn.getUser().getName()))

I get the following error after entering the username and password to connect within a Jupyter Notebook:

Username: xxxxxxx
OMERO Password: ········

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-34-de55f7b2c5a6> in <module>
     16 conn = connect(HOST, input("Username: "),
     17                getpass("OMERO Password: "))
---> 18 print("Connected as {}".format(conn.getUser().getName()))

~\Anaconda3\envs\omeropy\lib\site-packages\omero\gateway\__init__.py in getUser(self)
   2350         """
   2351         if self._user is None:
-> 2352             uid = self.getUserId()
   2353             if uid is not None:
   2354                 self._user = self.getObject(

~\Anaconda3\envs\omeropy\lib\site-packages\omero\gateway\__init__.py in getUserId(self)
   2332         """
   2333         if self._userid is None:
-> 2334             self._userid = self.getEventContext().userId
   2335         return self._userid
   2336 

~\Anaconda3\envs\omeropy\lib\site-packages\omero\gateway\__init__.py in getEventContext(self)
   2320         :rtype:     :class:`omero.sys.EventContext`
   2321         """
-> 2322         if self._ctx is None:
   2323             self._ctx = self._proxies['admin'].getEventContext()
   2324         return self._ctx

AttributeError: '_BlitzGateway' object has no attribute '_ctx'

Is there a configuration setting that I’m missing to enable CLI connections?

I think the port keyword argument is necessary with BlitzGateway

Dave,

If I add the port = 4064 argument to BlitzGateway, I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-37-3d67f5b720a4> in <module>
     16 conn = connect(HOST, input("Username: "),
     17                getpass("OMERO Password: "))
---> 18 print("Connected as {}".format(conn.getUser().getName()))

~\Anaconda3\envs\omeropy\lib\site-packages\omero\gateway\__init__.py in getUser(self)
   2350         """
   2351         if self._user is None:
-> 2352             uid = self.getUserId()
   2353             if uid is not None:
   2354                 self._user = self.getObject(

~\Anaconda3\envs\omeropy\lib\site-packages\omero\gateway\__init__.py in getUserId(self)
   2332         """
   2333         if self._userid is None:
-> 2334             self._userid = self.getEventContext().userId
   2335         return self._userid
   2336 

~\Anaconda3\envs\omeropy\lib\site-packages\omero\gateway\__init__.py in getEventContext(self)
   2320         :rtype:     :class:`omero.sys.EventContext`
   2321         """
-> 2322         if self._ctx is None:
   2323             self._ctx = self._proxies['admin'].getEventContext()
   2324         return self._ctx

AttributeError: '_BlitzGateway' object has no attribute '_ctx'

what is conn.connect() returning? If it is true, then you are getting a connection that is timing out. If it’s timing out, it could be the enableKeepAlive that’s causing trouble (memory is hazy, but I think that’s ms)

conn.connect() returns False.

I guess the thing to do now is check each of the parameters to BlitzGateway. Can you reach the host? Is the port exposed? Are you certain username and password are correct?

You might try connecting via the OMERO CLI (which you get for free with OMERO-py). omero login -h for instructions. I think the CLI might give more helpful error messages. If the parameters to the CLI work, they should work through BlitzGateway, in my experience.

Thanks for the tip about the omero login command. It still won’t connect, but at least I have an error that makes more sense:

WARNING:omero.client:..Ignoring error in client.__del__:<class 'Ice.SecurityException'> InternalException: Failed to connect: exception ::Ice::SecurityException { reason = SSL handshake failure: The parameter is incorrect. }

I’m sure that the username and password are correct. I was also able to connect with OMERO.insight, which I think uses the same ports? I checked if 4063 and 4064 are open and I was able to connect to both.

I’m on a Windows machine if that makes a difference. The server is running Ubuntu 18.04.

Ah yes, the Windows SSL thing. I think it’s an Ice issue. There are many relevant threads in this forum.

I don’t recall the best one to follow, but if you search “Windows omero ssl” you should get somewhere.

Windows, along with many recent Linux distributions, has more restrictive SSL requirements than supported by the default configuration of OMERO.

It’s possible to workaround this by configuring OMERO.server to use a self-signed certificate instead of the default anonymous ciphers. To make this easier we’ve released an omero-certificates plugin. Could you give that a go on your demo OMERO server?

If it doesn’t work could you show us your server configuration (omero config get)?

Simon, I’m not quite sure how to install that plugin to the Docker container. Is there a virtual omero.server environment within the container with pip? I also noticed that there is a Docker implementation here.

I was able to get a working connection with the Docker example here. Thanks again for pointing me in the right direction.

1 Like