python: error <type 'instance'>, ('No module named py', ), No module named py

David Hláčik david at hlacik.eu
Wed Jun 4 14:49:32 EDT 2008


Hello, what this beautifull mesage which is messing me whole day means :

*python: error <type 'instance'>, ('No module named py',), No module named
py*

as a result of class pdg.py which is called from nnrpd_auth.py.

To be detailed ... news server inn is calling that when doing
autentification , it calls nnrpd_auth.py where instance of my class is
hooked into inn , when authentification begins it calls method
authenticate(arguments) from pdg.

I will provide as many information as needed to solve this mistery, becouse
i really need to solve it.
Thanks!


#!/usr/bin/env python

import ldap
from nnrpd import syslog
class news:

        server = 'ldap://dev01.net.hlacik.eu'
        user_dn = 'cn=pdg,ou=Operators,o=Polarion'
        user_pw = 'Pdg1'

        connectcodes = {   'READPOST':200,
                           'READ':201,
                           'AUTHNEEDED':480,
                           'PERMDENIED':502
        }

        authcodes = {  'ALLOWED':281,
                       'DENIED':502
        }

        def newsauth(self,match_username,match_password):
                base_dn = 'ou=Users,o=Polarion'
                filter = "(uid=" +  match_username +  ")"
                attrs = ['userPassword']

                try :
                        l = ldap.initialize(self.server)
                        l.bind_s(self.user_dn, self.user_pw)
                        raw_res = l.search_s( base_dn, ldap.SCOPE_SUBTREE,
filter, attrs )
                        l.unbind()
                except ldap.SERVER_DOWN:
                        print "Error, server down"
                        return 2
                except ldap.INVALID_CREDENTIALS:
                        print "Error, invalid credentials"
                        return 2
                except ldap.LDAPError, e:
                        print "Error, %s" % e
                for results in raw_res:
                        (cn,search) = results
                        for password in search["userPassword"]:
                                if password == match_password: return 1

                return 0


        def authenticate(self, attributes):

                # just for debugging purposes
                syslog('notice', 'nnrpd_auth authenticate() invoked:
hostname %s, ipaddress
 %s, interface %s, user %s' % (\
                        attributes['hostname'], \
                        attributes['ipaddress'], \
                        attributes['interface'], \
                        attributes['user']))

                try:
                        syslog('notice', "result %s" %
self.newsauth('boss','bbbb'))
                except Exception, msg:
                        syslog('notice', "error %s, %s, %s" %
(type(msg),msg.args,msg))
                # do username passworld authentication
                #if self.newsauth(attributes['user'],
str(attributes['pass'])):
                #    syslog('notice', 'authentication by username
succeeded')
                #    return ( self.authcodes['ALLOWED'], 'No error' )
                #else:
                #    syslog('notice', 'authentication by username failed')
                #    return ( self.authcodes['DENIED'], 'Access Denied!')

-------------------

nnrpd_auth_py :


#
# This is a sample authentication and authorization module for python
# nnrpd hook
#
# For details, see the file doc/hook-python that came with INN.
#

#
# This file is loaded when one of the python_* readers.conf parameters
# is encountered. An instance of AUTH class is passed to nnrpd via
# set_auth_hook() function imported from nnrpd. The following methods
# of that class are known to nnrpd:
#
#   __init__()                  - Use this method to initilalize your
#                                 general variables or open a common
#                                 database connection. May be omitted.
#   access_init()               - Init function specific to access
#                                 control. May be omitted
#   access(attributes)          - Called when a python_access
#                                 statement is reached in the
#                                 processing of readers.conf. Returns
#                                 a dictionary of values representing
#                                 statements to be included in an
#                                 access group.
#   access_close()              - Called on nnrpd termination. Save
#                                 your state variables or close a
#                                 database connection. May be omitted
#   authen_init()               - Init function specific to
#                                 authentication. May be omitted
#   authenticate(attributes)    - Called when a python_auth statement
#                                 is reached in the processing of
#                                 readers.conf. Returns a response
#                                 code, an error string and an
#                                 optional string to appear in the
#                                 logs as the username.
#   authen_close()              - Called on nnrpd termination. Save
#                                 your state variables or close a database
#                                 connection. May be omitted
#   dynamic_init()              - Init function specific to
#                                 authentication. May be omitted
#   dynamic(attributes)         - Called whenever a reader requests either
#                                 read or post access to a
#                                 newsgroup. Returns None to grant
#                                 access, or a non-empty string (which
#                                 will be reported back to reader)
#                                 otherwise.
#   dynamic_close()             - Called on nnrpd termination. Save
#                                 your state variables or close a database
#                                 connection. May be omitted
#
# If there is a problem with return codes from any of these methods then
nnrpd
# will die and syslog the exact reason.
#
# There are also a few Python functions defined in nnrpd:
#
# set_auth_hook()               - Called by nnrpd as this module is loaded.
#                                 It is used to pass a reference to an
#                                 instance of authentication class to nnrpd.
# syslog()                      - An equivalent replacement for regular
syslog.
#                                 One consideration for using it is to
#                                 uniform nnrpd logging.

#
# Sample authentication and authorization class. It defines all methods
known
# to nnrpd.
#
# Import functions exposed by nnrpd. This import must succeed, or nothing
# will work!
from nnrpd import *
from pdg import *

myauth = news()

# ...and try to hook up on nnrpd. This would make auth object methods
visible
# to nnrpd.
try:
    set_auth_hook(myauth)
    syslog('notice', "authentication module successfully hooked into nnrpd")
except Exception, errmsg:
    syslog('error', "Cannot obtain nnrpd hook for authentication method: %s"
% errmsg[0])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080604/8a33912e/attachment.html>


More information about the Python-list mailing list