Python AttributeError

Python AttributeError - Python - Programmation

Marsh Posté le 11-06-2014 à 16:21:31    

Bonjour alors voilà j'ai sur mon code à la compilation un attributeError et je n'ai aucune idée d'où cela peut provenir...
 
Alors voilà mon code de base :
 
##Chemin avec les library
#!/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 = ()
 
 
 
 
class FirstUse():
     
    def __init__(self, cmd3):
        self.cmd3 = cmd3
 
     
 
 
cmd3.run("zyy", "Tutu2!" )
 
 
 
 
L’erreur que j'ai est la suivante :
 
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'
 
 
 
 
Voilà aussi si jamais ca peut aider la spécification de la fonction run que j'utilise :
 
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)
 
 
Voilà donc j'attends votre aide au plus vite…

Reply

Marsh Posté le 11-06-2014 à 16:21:31   

Reply

Marsh Posté le 11-06-2014 à 20:54:47    

Bah comme le message dit, il veut un sambaopts valide [:spamafote]

 

Mais en lisant le code, appeler les cmd_ directement n'a aucun sens, ce sont des implémentations des sous-commandes de l'outil shell samba-tool, si tu veux jouer avec programmatiquement faut taper directement dans samba.samdb.SamDB (et amis, genre samba.auth)


Message édité par masklinn le 11-06-2014 à 20:55:28

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 12-06-2014 à 15:22:52    

Alors du coup j'ai fais comme ça et tout marche comme il faut :
 
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_sambatool() #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)  
 
Par la suite je dois récupérer les mots de passe avec Hash sur un LDAP et j'aimerais juste savoir si avec cette méthode je vais pouvoir passer le Hash a Samba4?

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed