Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/link 时 出现 TypeError: 'NoneType' object is not subscriptable #23

Closed
jimzenn opened this issue Apr 29, 2018 · 3 comments
Closed

/link 时 出现 TypeError: 'NoneType' object is not subscriptable #23

jimzenn opened this issue Apr 29, 2018 · 3 comments
Labels

Comments

@jimzenn
Copy link

jimzenn commented Apr 29, 2018

版本信息

EH Forwarder Bot
Version: 2.0.0b10
Python version:
3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0]

Master channel:
    Telegram Master (blueset.telegram) 2.0.0b11 # Default profile

Slave channels:
    WeChat Slave (blueset.wechat) 2.0.0a12
    Facebook Messenger Slave (blueset.fbmessenger) 2.0.0b6

Middlewares:
    No middleware is enabled.

问题描述

之前可以正常使用,但最近:
在重复 Link 两个或以上联系人时,第二个及之后的联系人会出现一下 uncaught error。

重现步骤

同上

Verbose 日志

2018-04-29 16:57:46,409 [ERROR]: telegram.ext.dispatcher (dispatcher.process_update; dispatcher.py:301)
    An uncaught error was raised while processing the update
Traceback (most recent call last):
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 279, in process_update
    handler.handle_update(update, self)
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/telegram/ext/commandhandler.py", line 170, in handle_update
    return self.callback(dispatcher.bot, update, **optional_args)
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_telegram_master/chat_binding.py", line 256, in link_chat_
show_list
    return self.link_chat_gen_list(message.from_user.id, pattern=" ".join(args))
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_telegram_master/chat_binding.py", line 408, in link_chat_
gen_list
    source_chats=chats)
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_telegram_master/chat_binding.py", line 315, in slave_chat
s_pagination
    slave_chats = slave.get_chats()
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_wechat_slave/__init__.py", line 544, in get_chats
    return self.chats.get_chats()
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_wechat_slave/chats.py", line 108, in get_chats
    l.append(self.wxpy_chat_to_efb_chat(i))
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_wechat_slave/chats.py", line 88, in wxpy_chat_to_efb_chat
    efb_chat.members.append(self.wxpy_chat_to_efb_chat(i, False))
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_wechat_slave/chats.py", line 68, in wxpy_chat_to_efb_chat
    self.logger.debug("WXPY chat with ID: %s, name: %s, alias: %s;", chat.puid, chat.nick_name, chat.alias)
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_wechat_slave/wxpy/api/chats/chat.py", line 112, in puid
    return self.bot.puid_map.get_puid(self)
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_wechat_slave/wxpy/utils/puid_map.py", line 152, in get_pu
id
    new_caption = merge_captions(self.captions.get_key(puid), chat_caption)
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_wechat_slave/wxpy/utils/puid_map.py", line 247, in merge_
captions
    return tuple(new[i] or old[i] for i in range(4))
  File "/home/ubuntu/.conda/lib/python3.6/site-packages/efb_wechat_slave/wxpy/utils/puid_map.py", line 247, in <genex
pr>
    return tuple(new[i] or old[i] for i in range(4))
TypeError: 'NoneType' object is not subscriptable

@tingod
Copy link

tingod commented May 24, 2018

@blueset @Jim-Zenn 请参考:

原因分析:
/link/chat的时候,会遍历群里所有用户的信息。而很多群用户并非自己的好友,导致在进行merge caption或match caption操作的时候群用户old caption(tuple类型)为None,从而爆出exception。

解决方案:
修改efb_wechat_slave/wxpy/utils/puid_map.py中的match_captionsmerge_captions方法,加入old caption为None时的处理逻辑。代码如下。

efb_wechat_slave/wxpy/utils/puid_map.py

def match_captions(old, new):
    if new[0] and not old is None:
        for i in range(4):
            if old[i] and new[i] and old[i] != new[i]:
                return False
        return True

def merge_captions(old, new):
    if old is None:
        return new
    else:
        return tuple(new[i] or old[i] for i in range(4))

没有本地测试环境故未测试是否有衍生bug。

wolfsilver pushed a commit to wolfsilver/efb-wechat-slave that referenced this issue May 31, 2018
@IPv6Walker
Copy link

@tingod 亲测这种方法有效。今天也是换了不同的VPS测试,在第二次爬取列表的时候就会报错,一直显示处理中。修改代码之后就解决了。

@blueset
Copy link
Member

blueset commented Jun 17, 2018

感谢 @tingod 提供的 Patch,已在 9e07070 应用该更改。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants