我尝试使用 python 进行 BTC 监控,但它不起作用

时间:2021-04-27 07:09:36

标签: python python-3.x syntax-error

我是 Python 新手,当我运行此代码时,出现此错误,请帮忙。 Error screenshot

    import requests
from datatime import datatime 

#https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,JPY,EUR

URL = "https://min-api.cryptocompare.com/data/price?fsym={}&tsyms={}"

def get_price(coin,currency):
    try:
        respone = requests.get(URL.format(coin, currency)).json()
        return respons
    except:
        return False

while True:
    date_time = datetime.now()
    date_time = data_time.strftime("%d/%m/%Y %H:%M:%S")
    currentPrice = get_price(BTC,USD)
    if currentPrice:
        print(date_time, "BTC price: ", currentPrice, "$")

1 个答案:

答案 0 :(得分:0)

您是否安装了“请求”?

试试这个。终端上的“pip install requests”