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

Senthil Kumaran <[email protected]>
Newsgroups gmane.comp.python.egenix.user
Message-ID <[email protected]>
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


_______________________________________________________________________
eGenix.com User Mailing List                     http://www.egenix.com/
https://www.egenix.com/mailman/listinfo/egenix-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.