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

Exception: Friendship class can not be instanciated directly! #74

Closed
why2lyj opened this issue Jun 4, 2020 · 6 comments
Closed

Exception: Friendship class can not be instanciated directly! #74

why2lyj opened this issue Jun 4, 2020 · 6 comments
Labels
🐛 bug Something isn't working

Comments

@why2lyj
Copy link
Contributor

why2lyj commented Jun 4, 2020

2020-06-04 09:40:40,051 - Wechaty - INFO - receive event <EventFriendshipPayload(friendship_id='4358696816800085475')>
2020-06-04 09:40:40 INFO wechaty.py <friendship_listener> receive event <EventFriendshipPayload(friendship_id='4358696816800085475')>
2020-06-04 09:40:40,051 - FriendShip - INFO - Friendship constructor 4358696816800085475
2020-06-04 09:40:40 INFO friendship.py <init> Friendship constructor 4358696816800085475
2020-06-04 09:40:40 ERROR base_events.py <default_exception_handler> Exception in callback AsyncIOEventEmitter._emit_run.._callback(<Task finishe...d directly!')>) at /usr/local/lib/python3.7/site-packages/pyee/_asyncio.py:55
handle: <Handle AsyncIOEventEmitter._emit_run.._callback(<Task finishe...d directly!')>) at /usr/local/lib/python3.7/site-packages/pyee/_asyncio.py:55>
Traceback (most recent call last):
File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.7/site-packages/pyee/_asyncio.py", line 62, in _callback
self.emit('error', exc)
File "/usr/local/lib/python3.7/site-packages/pyee/_base.py", line 111, in emit
self._emit_handle_potential_error(event, args[0] if args else None)
File "/usr/local/lib/python3.7/site-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
raise error
File "/usr/local/lib/python3.7/site-packages/wechaty/wechaty.py", line 389, in friendship_listener
friendship = self.Friendship.load(payload.friendship_id)
File "/usr/local/lib/python3.7/site-packages/wechaty/user/friendship.py", line 81, in load
return cls(friendship_id)
File "/usr/local/lib/python3.7/site-packages/wechaty/user/friendship.py", line 69, in init
'Friendship class can not be instanciated directly!')
Exception: Friendship class can not be instanciated directly!

@wj-Mcat wj-Mcat added the 🐛 bug Something isn't working label Jun 8, 2020
@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Jun 8, 2020

This is a known bug in python-wechaty, please keep eye on new version. Thank you for your issue.

@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Jun 11, 2020

@why2lyj this bug is fixed now. You can install the latest python-wechaty version. If you have no question, I will close this issue in one day.

@why2lyj
Copy link
Contributor Author

why2lyj commented Jun 13, 2020

@why2lyj this bug is fixed now. You can install the latest python-wechaty version. If you have no question, I will close this issue in one day.

@wj-Mcat let's close this issue, it wont happen after using new version, but I will still keep eyes on it.

@why2lyj why2lyj closed this as completed Jun 13, 2020
@fish-ball fish-ball reopened this Jun 25, 2020
@fish-ball fish-ball reopened this Jun 25, 2020
@fish-ball
Copy link
Contributor

fish-ball commented Jun 25, 2020

The bug still exists.

Below is my bot code:

class DingDongBot(Wechaty):
    # ...
    async def on_friendship(self, friendship: Friendship):
        print(friendship)
        print(friendship.type()

async def main():
    bot = DingDongBot()
    await bot.start()

And when I make a add friendship request to the bot user, the below error occured:

2020-06-25 10:30:34,369 - Wechaty - INFO - receive <friendship> event <EventFriendshipPayload(friendship_id='8239572337309758562')>
INFO:Wechaty:receive <friendship> event <EventFriendshipPayload(friendship_id='8239572337309758562')>
2020-06-25 10:30:34,370 - FriendShip - INFO - Friendship constructor 8239572337309758562
INFO:FriendShip:Friendship constructor 8239572337309758562
2020-06-25 10:30:34,370 - Wechaty - ERROR - internal error <Friendship class can not be instanciated directly!>
ERROR:Wechaty:internal error <Friendship class can not be instanciated directly!>

@fish-ball
Copy link
Contributor

And then, I comment out the below lines under friendship.py:

def __init__(self, friendship_id: str):
        """
        initialization constructor for friendship
        """
        self.friendship_id = friendship_id
        self._payload: Optional[FriendshipPayload] = None

        log.info('Friendship constructor %s', friendship_id)

        # if self.__class__ is Friendship:
        #     raise Exception(
        #         'Friendship class can not be instanciated directly!')
        if self.puppet is None:
            raise Exception(
                'Friendship class can not be instanciated without a puppet!')

And then retry to make a friendship request to the bot user, another error occured:

INFO:FriendShip:Friendship constructor 8568343363800708622
Friendship
/home/alfred/app/python-wechaty-getting-started/python-wechaty/src/wechaty/user/friendship.py:128: RuntimeWarning: coroutine 'Friendship.ready' was never awaited
  self.ready()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2020-06-25 10:20:32,019 - Wechaty - ERROR - internal error <can"t load friendship payload>
ERROR:Wechaty:internal error <can"t load friendship payload>

@fish-ball
Copy link
Contributor

Finally the above issue is fixed in python-wecahty-puppet-hostie, and the main problem this issue is because the Friendship.is_ready function is incorrect. I've fixed them and here comes the PR.

wj-Mcat added a commit that referenced this issue Jun 27, 2020
Fixes issue #74 Friendship class cannot be instanciated directly, and…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants