я следующий код:.Python присвоить значение переменной, которая содержит («'{» и: персонажи
import subprocess
cmd = curl -X POST -H "Content-Type: application/json" -d '{ "auth_token": "e91a0ffe758c194f0d1d5896eb4daed0", "widget": "79c08a7e70f0253c3da2fab39e7cb89b", "title": "Something", "text": "Some text", "moreinfo": "Subtitle" }' http://collector.superviso.com
subprocess.call(cmd)
Я пытаюсь присвоить значение переменной, которая приводит к синтаксической ошибке Вот что бывает:
>>> cmd = curl -X POST -H "Content-Type: application/json" -d '{ "auth_token": "auth_token", "widget": "widget_id", "title": "Something", "text": "Some text", "moreinfo": "Subtitle" }' http://domain.com
File "<stdin>", line 1
cmd = curl -X POST -H "Content-Type: application/json" -d '{ "auth_token": "auth_token", "widget": "widget_id", "title": "Something", "text": "Some text", "moreinfo": "Subtitle" }' http://domain.com
^
SyntaxError: invalid syntax
Спасибо заранее
UPDATE01
тройная цитата. строку не позволяют мне присвоить значение еще subproces не работает
>>> cmd = """curl -X POST -H "Content-Type: application/json" -d '{ "auth_token": "e91a0ffe758c194f0d1d5896eb4daed0", "widget": "329bdbea887ad8e10e4e496f7a60f898", "title": "Something", "items":[{"label": "BOUGHT BREAD FOR", "value": "$999.99"}, {"label": "SOLD WATER FOR", "value": "$9,001.00"}] }' http://collector.superviso.com """
>>> subprocess.call(cmd)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 486, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1201, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
UPDATE02
Благодаря Adam`s сообщению (смотри выше), я был в состоянии sedn запрос без присвоения какой-либо переменной:
subprocess.call([
'curl',
'-X',
'POST',
'-H',
'Content-Type: application/json',
'-d',
'{ "auth_token": "e91a0ffe758c194f0d1d5896eb4daed0", "widget": "79c08a7e70f0253c3da2fab39e7cb89b", "title": "Something", "text": "Some text", "moreinfo": "Subtitle" }',
'http://collector.superviso.com'
])
+1. и вызвать 'cmd' в качестве подпроцесса:' subprocess.check_call (shlex.split (cmd)) ' – jfs