Pythonスクリプトからldaplistコマンドを実行しています(ldapモジュールを保証するのに十分ではありません):
storage = Popen(["ldaplist", "-l", "passwd", "bob"], stdout=PIPE, stderr=PIPE)
stdout, stderr = storage.communicate()
この後、「stderr」がldaplistからの典型的な「そのようなユーザーはいません」エラー(「ldaplist:オブジェクトが見つかりません」)に一致するかどうかに基づいてアクションを実行したいと思います
これは機能しません:
if stderr == "ldaplist: Object not found":
print "No entry exists in passwd for the username you have input."
sys.exit(1)
ただし、これは次のことを行います。
if re.search("^ldaplist: Object not found", stderr):
print "No entry exists in passwd for the username you have input."
sys.exit(1)
「機能しない」とは、if ブロックに分類されないことを意味します。したがって、コードの残りの部分が実行され、あらゆる種類のエラーが発生します。 (stderrに値がある場合はそうではありません)。
上記のスニペットが失敗していることには関係ないと思いますが、エラーは具体的には次のとおりです。
Traceback (most recent call last):
File "./ldaplistTest3.py", line 43, in <module>
testPasswd = Passwd(dn, sambaProfilePath, sambaHomePath)
NameError: name 'dn' is not defined
(コードがその時点に達したことがないため、dn は定義されていません)