0

I try to withdraw crypto currencies from my Poloniex wallet to external wallets in python with the Poloniex module, which works pretty good with the following code:

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"])

If there is no error during withdrawal process, everything is fine. If there is an error (I don't have enough balance or address is wrong), it will print doesn't work, as intended. If I print r, I will get the following error:

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.

Now I want to print this message from the error: Not enough LTC.

Is it possible to print this message?

Phil
  • 65
  • 8

1 Answers1

1

If you save the Exception in a variable, you can print the error message easily:

except PoloniexCommandException as e:
    print(e)
restart4tw
  • 31
  • 3