0
我有一個子進程返回,它包含一個方法來驗證憑據,並返回這樣的響應:使用處理subprocess.check_output用引號
{
"isvalid" : false
}
林此獲得響應,並檢查憑據通過了測試:
def slraddresstest():
while True:
solarcoin_address = raw_input ("What is your SolarCoin Address: ")
output = subprocess.check_output(['solarcoind', 'validateaddress', solarcoin_address], shell=False)
if output != "{\"isvalid\" : false}"
return solarcoin_address
else:
print ("Error: SolarCoin address invlaid, check and try again")
但上運行的代碼我得到:
if output != "{\"isvalid\" : false}"
^
SyntaxError: invalid syntax
我阿爾斯o試過if output != '{"isvalid" : false}'
和if output != """{"isvalid" : false}"""
,但得到類似的語法錯誤。
Arghh! 謝謝,很抱歉! – Scalextrix
我的一段代碼仍然沒有工作,當我測試它並輸入一個無效的solarcoin_address時,它不會給出錯誤。 輸出看起來像一個字典,所以我做了如果輸出['isvalid']!='false':但是這給了一個TypeError:字符串索引必須是整數,而不是str。所以顯然輸出是一個字符串,但我似乎無法匹配它,是因爲換行符? – Scalextrix
好吧,我想通過試驗找出一個錯誤,我可以從output = subprocess.check_output(['solarcoind','validateaddress',solarcoin_address],shell = False)[18:-3]去除輸出中不需要的東西,只給我'假' – Scalextrix