Mar-11-2022, 12:10 PM
(This post was last modified: Mar-11-2022, 04:00 PM by DeaD_EyE.
Edit Reason: censored exposed information
)
You can use
The
you can use triple single quotes or triple double quotes. Example with triple double quotes:
Instead, use
raises a CalledProcessError if the called process returns with non-zero. If the program was not found, a
shlex.split
to split the str
, like the shell does it.The
SyntaxError
is raised because the quotes are wrong. If you have mixed single quotes and double quotes in one string,you can use triple single quotes or triple double quotes. Example with triple double quotes:
name = """This "is" " ' A ' Test''' """But this does not address the problem itself. The use of
os.system
should be avoided.import shlex command = shlex.split(""" censored '""") print(command)
Output:['ldapsearch', ...]
os.system
should not be used because it's limited (stdout does not return) and it has security issues.Instead, use
subprocess.Popen
or subprocess.check_output
. subprocess.check_output
raises a CalledProcessError if the called process returns with non-zero. If the program was not found, a
FileNotFoundError
is raised. If the program exists, but you're not allowed to run the program (missing execute permission), a PermissionError
is raised.from subprocess import CalledProcessError, check_output def search(): cmd = [ 'ldapsearch', ... ] try: return check_output(cmd, encoding="utf8") except CalledProcessError: pass except FileNotFoundError: raise RuntimeError("The program `ldapsearch` is not installed.")Then you can use the function also to submit different addresses to your ldapsearch.
from subprocess import CalledProcessError, check_output def search(ip, port=3268): cmd = [ 'ldapsearch', '-H', f'ldap://{ip}:{port}', ..., ] try: return check_output(cmd, encoding="utf8") except CalledProcessError: pass except FileNotFoundError: raise RuntimeError("The program `ldapsearch` is not installed.")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!