django-wkhtmltopdf icon indicating copy to clipboard operation
django-wkhtmltopdf copied to clipboard

Options with multiple values get split to send to subprocess

Open noelevans opened this issue 5 months ago • 0 comments

When an option like --custom-header Authorization my-token is received this must be broken in to 3 strings to be given to subprocess.Popen

  • 'custom-header'
  • 'Authorization'
  • 'my-token'

With the previous code where "Authorization my-token" was one string, Popen does not correctly pass both arguments with --custom-header. Consequently wkhtmltopdf ignores any --custom-header instruction sent to it from django-wkhtml. The problem can be seen by running these commands:

import subprocess cmd = ['curl', '--dump-header output', 'https://api.github.com'] subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() (b'', b"curl: option --dump-header output: is unknown\ncurl: try 'curl --help' for more information\n")

If you change the above command to be

cmd = ['curl', '--dump-header', 'output', 'https://api.github.com']

then the call works and makes a file called "output" containing header information.

noelevans avatar Sep 26 '24 07:09 noelevans