[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [HTCondor-users] Problems using classad.quote in the Python bindings



Hi Gaëtan,

As you have probably read from the documentation Classad.quote() converts a python string into a classad string. A classad string is wrapped in double quotes. That is why the passed json '{"Hello":"World"}'  converts to "{\"Hello\":\"World\"}" which cause your failure after setting arguments to ' '.join(command[1:]). I believe arguments gets wrapped in double quotes making an invalid arguments string of "arg1 arg2 "{\"Hello\":\"World\"}"". I think if you did command[6] = Classad.quote(command[6]) and then convert the first and last characters (the wrapping double quotes) to single quotes you should have a valid argument string.

Hope this helps,
Cole Bollig

From: HTCondor-users <htcondor-users-bounces@xxxxxxxxxxx> on behalf of Gaetan Geffroy <gage@xxxxxxxxx>
Sent: Friday, December 9, 2022 12:15 PM
To: htcondor-users@xxxxxxxxxxx <htcondor-users@xxxxxxxxxxx>
Subject: [HTCondor-users] Problems using classad.quote in the Python bindings
 

I am trying to submit jobs using Python, and there is some JSON in the arguments.

I am trying to use classad.quote to make these json strings understandable by Condor, but it does not look like it has the desired effect.

Here is what I am doing:

  1. The command to send is stored in a list (ex: [‘ls’, ‘-alh’, ‘/root’])
    1. One of these arguments, in my case, is a dict transformed into a JSON using json.dumps
  2. I separate the executable and the arguments:
    1. executable = command[0]
    2. command[6] = classad.quote(command[6])           # Here I try to sanitize my JSON
    3. arguments = ‘ ’.join(command[1:])
  3. I create the submit object:

 

job = {

            "executable": executable,                   # Executable

            "transfer_executable": False,               # The executable is expected to be present in the docker image

            "arguments": arguments,                     # Arguments for the executable

            "universe": "docker",                       # Run job in Docker container

            "docker_image": docker_image,               # Docker image to be used

            "environment": self.convert_envvars(),      # Set the environment variables in container

            "should_transfer_files": "YES",             # Enable file transfer

            "transfer_input_files": inputs,             # Transfer files

            "output": self.stdout_filename,             # File where the stdout of the container will be written

            "error": self.stderr_filename,              # File where the stderr of the container will be written

        }

 

But then I get: ERROR:root:Condor Job Submission failed: Found illegal unescaped double-quote

 

After playing around a bit, it looks like the classad.quote function does not do what it is supposed to do:

Isn’t it supposed to escape all “ characters and surround everything with ‘ ’ ?

 

Thanks,

 

Gaëtan Geffroy

 

 


Gaetan Geffroy
Junior Software Engineer, Space

Terma GmbH
Europaarkaden II, Bratustraße 7, 64293 Darmstadt, Germany
T +49 6151 86005 43 (direct)  •  T +49 6151 86005-0
Terma GmbH - Sitz Darmstadt  •  Handelsregister Nr.: HRB 7411, Darmstadt
Geschäftsführer: Poul Vigh / Steen Vejby Sørensen
www.terma.com • 
LinkedinTwitterInstagramYoutube


Attention:
This e-mail (and attachment(s), if any) - intended for the addressee(s) only - may contain confidential, copyright, or legally privileged information or material, and no one else is authorized to read, print, store, copy, forward, or otherwise use or disclose any part of its contents or attachment(s) in any form. If you have received this e-mail in error, please notify me by telephone or return e-mail, and delete this e-mail and attachment(s). Thank you.