AttributeError, I don't know how to resolv it !!

This is the place for queries that don't fit in any of the other categories.

AttributeError, I don't know how to resolv it !!

Postby irastak » Wed Jun 11, 2014 2:10 pm

Hello, I have an AttributeError and I really don't know why...

I give you some piece of my code, to begin the source code :

Code: Select all
##way of my libraries
#!/usr/local/samba/lib/python2.7/site-packages/samba/netcmd

import sys



# Find right direction when running from source tree
sys.path.insert(1, "/usr/local/samba/lib/python2.7/site-packages/samba/netcmd")

# make sure the script dies immediately when hitting control-C,
# rather than raising KeyboardInterrupt. As we do all database
# operations using transactions, this is safe.
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)


from samba.netcmd.main import cmd_sambatool
cmd = cmd_sambatool()
subcommand = None
args = ()

from samba.netcmd.user import cmd_user
cmd2 = cmd_user()
subcommand = None
args = ()

from samba.netcmd.user import cmd_user_create
cmd3 = cmd_user_create()
subcommand = None
args = ()



#I think this is useless
class FirstUse():
   
    def __init__(self, cmd3):
        self.cmd3 = cmd3

   


cmd3.run("zyy", "Tutu2!")

The error is this one :
Code: Select all
Traceback (most recent call last):
  File "/root/workspaceTest/testPython/src/FirstUse.py", line 49, in <module>
    cmd3.run("zyy", "Tutu2!")
  File "/usr/local/samba/lib/python2.7/site-packages/samba/netcmd/user.py", line 160, in run
    lp = sambaopts.get_loadparm()
AttributeError: 'NoneType' object has no attribute 'get_loadparm'

And now I post you this, I don't know if this could help you to help me but this is the specification of the run() function :
Code: Select all
user.cmd_user_add.run(self, username, password=None, credopts=None, sambaopts=None, versionopts=None, H=None, must_change_at_next_login=False, random_password=False, use_username_as_cn=False, userou=None, surname=None, given_name=None, initials=None, profile_path=None, script_path=None, home_drive=None, home_directory=None, job_title=None, department=None, company=None, description=None, mail_address=None, internet_address=None, telephone_number=None, physical_delivery_office=None)

So, now I'm waiting to your help...
Last edited by Mekire on Wed Jun 11, 2014 3:32 pm, edited 2 times in total.
Reason: Code tags. Locked. Moved.
irastak
 
Posts: 5
Joined: Wed Jun 11, 2014 1:57 pm

Re: AttributeError, I don't know how to resolv it !!

Postby Yoriz » Wed Jun 11, 2014 5:23 pm

Looking at the error and the code i found at https://github.com/avati/samba/blob/master/python/samba/netcmd/user.py
The run method needs to be passed in a sambaopts because it is trying to call the method get_loadparm, because you never gave run a sambaopts it defaulted to None which has no method get_loadparm.
It looks like the following line will error after that because the passed in credopts will try to call the method get_credentials. you'll need to find out which of all those paramters that are defaulted to None actually do need something passed in ofr the code to work properly.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 833
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Other Question

Postby irastak » Thu Jun 12, 2014 1:21 pm

I made it diferently, I use the samba-tool commands...

So, I made it like this now and the running is good :


Code: Select all
import sys

# Find right direction when running from source tree

sys.path.insert(0, "/usr/local/samba/lib/python2.7/site-packages")

# make sure the script dies immediately when hitting control-C,

# rather than raising KeyboardInterrupt. As we do all database

# operations using transactions, this is safe.

import signal

signal.signal(signal.SIGINT, signal.SIG_DFL)

#Importation de la bonne classe

from samba.netcmd.main import cmd_sambatool

cmd = cmd_samba]import sys

# Find right direction when running from source tree

sys.path.insert(0, "/usr/local/samba/lib/python2.7/site-packages")

# make sure the script dies immediately when hitting control-C,

# rather than raising KeyboardInterrupt. As we do all database

# operations using transactions, this is safe.

import signal

signal.signal(signaltool() #on declare cmd un objet de la classe

subcommand = "user" #On utilise la commande user de la classe cmd_sambatool

args = ("add","zaaa","Zaaa!?4","--surname=zaa","--initials=zzaa") #args prend la valeur de l'action a executer et on lui fournit les informations/Options necessaires !!

#Ici declaration d'une nouvelle action a utiliser

args2 = ("delete", "zii")

if len(sys.argv) > 1:

subcommand = sys.argv[1]

if len(sys.argv) > 2:

args = sys.argv[2:]

args2 = sys.argv[2:]

try:

retval = cmd._run("samba-tool", subcommand, *args) #_run execute la bonne commande

except SystemExit, e:

retval = e.code

except Exception, e:

cmd.show_command_error(e)

retval = 1

try:

retval = cmd._run("samba-tool", subcommand, *args2)

except SystemExit, e:

retval = e.code

except Exception, e:

cmd.show_command_error(e)

retval = 1

sys.exit(retval)


After I may to take password with a Hash on a LDAP server and I would like to know if with this method I could put the Hash to Samba4?
Last edited by irastak on Fri Jun 13, 2014 6:25 am, edited 1 time in total.
irastak
 
Posts: 5
Joined: Wed Jun 11, 2014 1:57 pm

Re: AttributeError, I don't know how to resolv it !!

Postby stranac » Thu Jun 12, 2014 2:57 pm

Read this and edit your post: viewtopic.php?t=145
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 2 guests