我必須以這種形式準確發送 curl 才能在 cli 中獲得回應
curl -d '{"id":0,"params":["aa:aa:00:00:00:00",["mixer","volume","80"]],"method":"slim.request"}' http://localhost:9000/jsonrpc.js
curl -d '{"id":0,"params":["aa:aa:00:00:00:00",["playlist","play","/home/pi/mp3/File.mp3"]],"method":"slim.request"}' http://localhost:9000/jsonrpc.js
在我的腳本中運行上面的命令,我得到一個撇號的語法錯誤
File "./updateTimers.py", line 126
strVolume = curl -d '{"id":0,"params":["aa:aa:00:00:00:00",["mixer","volume","80"]],"method":"slim.request"}' http://localhost:9000/jsonrpc.js
^
SyntaxError: invalid syntax
如果我更改撇號和引號,那么我的 python 腳本也不喜歡該語法。很高興任何建議。至少我需要一個一個地運行這兩個命令。
strVolume = curl -d '{"id":0,"params":["aa:aa:00:00:00:00",["mixer","volume","80"]],"method":"slim.request"}' http://localhost:9000/jsonrpc.js
strPlayMP3Command = curl -d '{"id":0,"params":["aa:aa:00:00:00:00",["playlist","play","/home/pi/adhan/mp3/Adhan-Makkah.mp3"]],"method":"slim.request"}' http://localhost:9000/jsonrpc.js
uj5u.com熱心網友回復:
如果我正確理解您的問題,您希望curl -d ...成為 Python 中的字串。為此,您還必須curl用引號括起來:strVolume = "curl -d '{\"id\": 0, ...}' ...". 確保你轉義里面的引號。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/459342.html
標籤:Python python-3.x 卷曲
