ebellocchia / telegram_crypto_price_bot

Telegram bot for displaying cryptocurrencies prices and charts
MIT License
53 stars 21 forks source link

NoneType when value isn't returned #5

Closed fouille closed 1 year ago

fouille commented 1 year ago

Hello,

I've an error :

2022-12-15 09:17:27,648 ERROR - int() argument must be a string, a bytes-like object or a number, not 'NoneType'                                                        
Traceback (most recent call last):                                                                                                                                      
  File "/usr/local/lib/python3.9/dist-packages/pyrogram/dispatcher.py", line 242, in handler_worker                                                                     
    await self.loop.run_in_executor(                                                                                                                                    
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run                                                                                               
    result = self.fn(*self.args, **self.kwargs)                                                                                                                         
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/bot/bot_base.py", line 107, in <lambda>                                                        
    curr_type(lambda client, message: curr_cfg["callback"](self, client, message),                                                                                      
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/bot/bot_handlers_cfg.py", line 87, in <lambda>                                                 
    "callback": lambda self, client, message: self.DispatchCommand(client,                                                                                              
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/bot/bot_base.py", line 120, in DispatchCommand                                                 
    self.cmd_dispatcher.Dispatch(client, message, cmd_type, **kwargs)                                                                                                   
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/command/command_dispatcher.py", line 124, in Dispatch                                          
    cmd_class.Execute(message, **kwargs)                                                                                                                                
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/command/command_base.py", line 96, in Execute                                                  
    self._ExecuteCommand(**kwargs)                                                                                                                                      
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/command/commands.py", line 150, in _ExecuteCommand                                             
    coin_info_sender.SendMessage(self.cmd_data.Chat(), coin_id, coin_vs, last_days)                                                                                     
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/info_message_sender/coin_info_message_sender.py", line 94, in SendMessage                      
    self.chart_price_info_msg_sender.SendMessage(chat, coin_id, coin_vs, last_days)                                                                                     
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/info_message_sender/info_message_sender_base.py", line 61, in SendMessage                      
    self.last_sent_msg = self._SendMessage(chat, *args, **kwargs)                                                                                                       
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/info_message_sender/chart_price_info_message_sender.py", line 67, in _SendMessage              
    price_info = self._CoinGeckoPriceApi().GetPriceInfo(args[0], args[1])                                                                                               
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/coingecko/coingecko_price_api.py", line 57, in GetPriceInfo                                    
    return PriceInfo(coin_info, coin_vs)                                                                                                                                
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/price_info/price_info.py", line 73, in __init__                                                
    PriceInfoTypes.MARKET_CAP_RANK: Utils.StrToInt(coin_data["market_data"]["market_cap_rank"]),                                                                        
  File "/usr/local/lib/python3.9/dist-packages/telegram_crypto_price_bot/utils/utils.py", line 66, in StrToInt
    return int(s)                                                                                                                                                       
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

When I try on new crypto, coingecko return null value in market cap.

My workaround in telegram_crypto_price_bot/utils/utils.py change block line 63 to :

    # Convert string to integer
    @staticmethod
    def StrToInt(s: str) -> int:
        if s is None:
            res = int(0)
        else:
            res = int(s)
        return res
ebellocchia commented 1 year ago

Hello, thanks for the finding, it has never happened to me to get None. I'll check and fix it.

Regards Emanuele