Skip to content

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.
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