0

我尝试使用 Poloniex 模块将加密货币从我的 Poloniex 钱包提取到 python 中的外部钱包,该模块与以下代码配合得很好:

from poloniex import Poloniex
from poloniex import PoloniexCommandException

polo = Poloniex("my_api_key", "my_api_secret")

try: 
    r = polo.withdraw(currency = "LTC", amount = "0.5", address = "MH...W5")

except PoloniexCommandException:
    print("doesn't work")

else:
    print("successful")
    print(r["response"])

如果提款过程中没有错误,一切都很好。如果出现错误(我没有足够的余额或地址错误),它将doesn't work按预期打印。如果我打印r,我会收到以下错误:

Traceback (most recent call last):
  File "c:\Users\phil\Desktop\Python\poloniextest.py", line 12, in <module>
    r = polo.withdraw(currency = "LTC", amount = "0.5", address = "MH...W5")
  File "C:\Users\phils\AppData\Local\Programs\Python\Python39\lib\site-packages\poloniex\poloniex.py", line 300, in withdraw
    return self._private('withdraw', currency=currency, amount=amount,
  File "C:\Users\phil\AppData\Local\Programs\Python\Python39\lib\site-packages\poloniex\poloniex.py", line 50, in _fn
    raise PoloniexCommandException(respdata['error'])
poloniex.exceptions.PoloniexCommandException: Not enough LTC.

现在我想从错误中打印此消息:Not enough LTC.

是否可以打印此消息?

4

1 回答 1

1

如果将异常保存在变量中,则可以轻松打印错误消息:

except PoloniexCommandException as e:
    print(e)
于 2021-04-07T16:26:50.770 回答