我想檢查一個簡單的標誌是真或假,但我的IF語句失敗,它不會給我正確的結果,希望有人可以幫助!python如果語句失敗
我使用(在python3.6)這個網址
https://bittrex.com/api/v1.1/public/getticker?market=usdt-btc
的GET請求,它應該(在瀏覽器URL)返回看起來像這樣的數據:
{"success":true,"message":"","result":{"Bid":18362.00000000,"Ask":18399.00000000,"Last":18362.00000000}}
下面是我的程序:
import sys
import time
import requests
import json
import os
BTCtick = 'https://bittrex.com/api/v1.1/public/getticker?market=usdt-btc'
reqBTC = requests.get('https://bittrex.com/api/v1.1/public/getticker? market=usdt-btc').text
BTCdata = json.loads(reqBTC)
testResult = BTCdata['success']
print("=============================")
print("success content: ", BTCdata['success'])
if (testResult == 'True'):
print("IF: success flag is TRUE")
else:
print("IF: success flag is FALSE")
print("=============================")
print("result content: ", BTCdata['result'])
print("Bid: ", BTCdata['result'] ['Bid'], sep='')
print("Ask: ", BTCdata['result'] ['Ask'], sep='')
print("Last: ", BTCdata['result'] ['Last'], sep='')
print("=============================")
exit()
輸出在控制檯看起來是這樣的:
=============================
success content: True
IF: success flag is FALSE
=============================
result content: {'Bid': 18420.0, 'Ask': 18439.99999999, 'Last': 18439.99999999}
Bid: 18420.0
Ask: 18439.99999999
Last: 18439.99999999
=============================
任何想法我在這裏失蹤?我確信它很簡單 請幫助我,我對python有點新,並且發現有什麼不對,我在過去兩天一直在閱讀很多內容,但是找不到問題!
你使用文字''True''但也許它應該是布爾值'True' – furas
剛注意,謝謝@chris – elanor
'True'!=''True'' =''true'' –