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

Error while restoring session #1

Closed
MhankBarBar opened this issue Nov 17, 2021 · 6 comments
Closed

Error while restoring session #1

MhankBarBar opened this issue Nov 17, 2021 · 6 comments

Comments

@MhankBarBar
Copy link

MhankBarBar commented Nov 17, 2021

Sorry in advance, I don't really understand python, but I'm trying to save the session and then restore it again

My code is like this

from os import path
from wamd.common import AuthState

@inlineCallbacks
def onConnect(connection):
    print("\nConnection 1: %r" % (connection, ))
    # check if session path if exists
    # and restore the session
    if path.exists("session.json"):
        session = eval(open("session.json").read())
        connection.authState = AuthState.fromJson(session)
    else:
        connection.on("qr", handleQr)

    # the new connection after successfull authentication
    # will be different than provided the first connection
    # since the connection will automatically be restarted
    # after authentication.
    connection = yield connection.authenticate()

    # check if session file not in path
    # and save session to file
    if not path.exists("session.json"):
        open("session.json","w").write(str(connection.authState.toJson()))
    connection.on("inbox", inboxReceiver)
    print("\nConnection 2: %r" % (connection, ))

but it fails and can't restore session

@serenity-77
Copy link
Owner

Is there any exception or failure printed on the screen?

@MhankBarBar
Copy link
Author

MhankBarBar commented Nov 17, 2021

Sorry, I've been able to save and then restore it again, this issued solve when I store session in MultiDeviceWhatsAppClientProtocol

But showing error like this
Screenshot_2021-11-17-21-48-29-80

@MhankBarBar MhankBarBar reopened this Nov 17, 2021
@serenity-77
Copy link
Owner

sepertinya masalah pada saat decrypt pesan masuk
sedang di lakukan perbaikan.

@serenity-77 serenity-77 added bug Something isn't working and removed bug Something isn't working labels Nov 18, 2021
@MhankBarBar MhankBarBar changed the title This library can't save and restore session? Error while restoring session Nov 18, 2021
@MhankBarBar
Copy link
Author

Gimana cara handle event new message setelah restore session?

@a5r0n
Copy link

a5r0n commented Dec 2, 2021

u need to restore the auth_state before u run the reactor. (e.g in the factory function)

something like:

def protocol_factory():
    # Do any initialization here, such as reading session file
    # to be supplied to the protocol/connection.
    if path.exists("auth.json"):
        with open("auth.json") as f:
            print("Loading auth state from auth.json")
            auth_state = AuthState.fromJson(json.loads(f.read()))
    else:
        auth_state = AuthState()

    return MultiDeviceWhatsAppClient(authState=auth_state)

@MhankBarBar
Copy link
Author

u need to restore the auth_state before u run the reactor. (e.g in the factory function)

something like:

def protocol_factory():
    # Do any initialization here, such as reading session file
    # to be supplied to the protocol/connection.
    if path.exists("auth.json"):
        with open("auth.json") as f:
            print("Loading auth state from auth.json")
            auth_state = AuthState.fromJson(json.loads(f.read()))
    else:
        auth_state = AuthState()

    return MultiDeviceWhatsAppClient(authState=auth_state)

I've been trying this for a long time, but still can't handle events

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

No branches or pull requests

3 participants