Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options with multiple values get split to send to subprocess #204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

noelevans
Copy link

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.

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.
wkhtmltopdf/utils.py Outdated Show resolved Hide resolved
wkhtmltopdf/utils.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants