[egenix-users] Exception exceptions.AttributeError - Depending upon the naming of the module ( connector.py / error_connector.py)

Senthil Kumaran orsenthil at gmail.com
Mon Feb 9 21:17:33 CET 2009


Hello,

This is a strange issue which is occurring with how I name a particular module.
Is this anyway related to namespace pollution?If yes, can some more
details/ information be shared?

I am going to present the snippets in-line (as they are very short)
and show you the test conditions.

Case 1: Working Case

# test_mxconnect.py
from global_connector import initialize_connector

CONFIG_PATH = '/usr/local/etc/client-config.ini'
CONNECTION_STRING = 'DSN=jiva_trunk;UID=jiva_user;PWD=jiva_user'

if __name__ == '__main__':
    initialize_connector(connector_name='mxOdbcConnect',
client_config_path = CONFIG_PATH)
    from global_connector import MsSQLdbapi
    if not hasattr(MsSQLdbapi, 'connect'):
        db_api = MsSQLdbapi.open()
    print MsSQLdbapi, db_api

-------------------------------------------------------------------------------------------------------------------------------------
#global_connector.py
def initialize_connector (connector_name='mxODBC', **kwargs):
    global MsSQLdbapi
    try:
        if connector_name == 'mxODBC':
            pass
        elif connector_name == 'mxOdbcConnect':
            from mx.ODBCConnect.Client import ServerSession
            config_path = kwargs.get('client_config_path')
            if not config_path:
                raise AssertionError, "Expected keyword arg: client_config_path"
            MsSQLdbapi = ServerSession(config_path)
    except ImportError,e:
        print e
        raise
----------------------------------------------------------------------------------------------------------------

Case 2:
Do a $mv global_connector.py  connector.py
And in test_mxconnect.py, replace global_connector with connector.py

# test_mxconnect.py
from connector import initialize_connector    # Offender in the module name

CONFIG_PATH = '/usr/local/etc/client-config.ini'
CONNECTION_STRING = 'DSN=jiva_trunk;UID=jiva_user;PWD=jiva_user'

if __name__ == '__main__':
    initialize_connector(connector_name='mxOdbcConnect',
client_config_path = CONFIG_PATH)
    from connector import MsSQLdbapi       # Offender in the module name
    if not hasattr(MsSQLdbapi, 'connect'):
        db_api = MsSQLdbapi.open()
    print MsSQLdbapi, db_api


The Error message, I get after script execution is:

Exception exceptions.AttributeError: "'NoneType' object has no
attribute 'EndOfCommunicationRequestObject'" in <bound method
ServerSession.close of <mxODBC Connect ServerSession with
<TCPConnection to 192.168.1.21:6632 (plain-text)>>> ignored

Case 3:  Failure Scenario.

If I name the module global_connector.py as error_connector.py, and
use that in the test_mxconnect.py, I still get the error Exception at
the end of completion of the script.


Any explanations?

-- 
-- 
Senthil



More information about the egenix-users mailing list