!JiiOHXrIUCtcOJsZCa:matrix.org

nio

231 Members
The nio matrix python library | Latest release 0.18.3 https://pypi.org/project/matrix-nio/ | Documentation: https://matrix-nio.readthedocs.io/en/stable/113 Servers

Load older messages


SenderMessageTime
20 Jun 2021
@brendan:abolivier.bzhBrendan Abolivier changed their profile picture.16:14:29
21 Jun 2021
@poljar:matrix.orgpoljar changed the room topic to "The nio matrix python library | Latest release 0.18.3 https://pypi.org/project/matrix-nio/ | Documentation: https://matrix-nio.readthedocs.io/en/stable/" from "The nio matrix python library | Latest release 0.18.2 https://pypi.org/project/matrix-nio/ | Documentation: https://matrix-nio.readthedocs.io/en/stable/".09:38:36
@realdwd:matrix.orgDWD-Daniel joined the room.20:04:13
@realdwd:matrix.orgDWD-DanielHey, I'm new to matrix and the nio api. I am running the basic example (https://matrix-nio.readthedocs.io/en/latest/examples.html#a-basic-client) however the room uses encryption. I've made a backup of the keys for my client. How would i supply those to teh AsyncClient?20:05:55
@poljar:matrix.orgpoljarbackup as in a file containing the room keys?20:14:36
@realdwd:matrix.orgDWD-DanielI was asked to save or copy the key20:15:51
@realdwd:matrix.orgDWD-DanielI elected to copy the string to a p/w manager for safekeeping20:16:11
@realdwd:matrix.orgDWD-Danielfor my user - i don't think it was for the roo20:16:46
@realdwd:matrix.orgDWD-Danielroom*20:16:55
@poljar:matrix.orgpoljarthat sounds like the server-side backup, this isn't supported20:17:27
@poljar:matrix.orgpoljaryou could export the keys to a file and then import them in nio https://matrix-nio.readthedocs.io/en/latest/nio.html#nio.AsyncClient.import_keys20:17:44
@realdwd:matrix.orgDWD-Danielok I'll give that a go thank you20:19:23
@realdwd:matrix.orgDWD-Daniel should import_keys() be invoked before or after login() 20:36:23
@poljar:matrix.orgpoljarafter20:38:58
@realdwd:matrix.orgDWD-Daniel

Right, that leads to

nio.exceptions.LocalProtocolError: Matrix store and olm account is not loaded.
async def main() -> None:
    client = AsyncClient("https://matrix.org", uname)
    client.add_event_callback(message_callback, RoomMessageText)

    print(await client.login(pw))

    client.import_keys(  # This instruction causes the exception
        '/home/daniel/Downloads/element-keys.txt',
        pasphrase,
    )

    await client.sync_forever(timeout=30000) # milliseconds

asyncio.get_event_loop().run_until_complete(main())

Do i need to initialized a store or some olm

20:43:35
@realdwd:matrix.orgDWD-Daniel *

Right, that leads to

nio.exceptions.LocalProtocolError: Matrix store and olm account is not loaded.
async def main() -> None:
    client = AsyncClient("https://matrix.org", uname)
    client.add_event_callback(message_callback, RoomMessageText)

    print(await client.login(pw))

    client.import_keys(
        '/home/daniel/Downloads/element-keys.txt',
        pasphrase,
    )

    await client.sync_forever(timeout=30000) # milliseconds

asyncio.get_event_loop().run_until_complete(main())

Do i need to initialized a store or some olm

20:43:44
@realdwd:matrix.orgDWD-Daniel *

Right, that leads to

nio.exceptions.LocalProtocolError: Matrix store and olm account is not loaded.
async def main() -> None:
    client = AsyncClient("https://matrix.org", uname)
    client.add_event_callback(message_callback, RoomMessageText)

    print(await client.login(pw))

    client.import_keys(  # This instruction causes the exception
        '/home/daniel/Downloads/element-keys.txt',
        pasphrase,
    )

    await client.sync_forever(timeout=30000) # milliseconds

asyncio.get_event_loop().run_until_complete(main())

Do i need to initialized a store or some olm

20:44:36
@poljar:matrix.orgpoljaryou need to provide a store path20:44:42
@realdwd:matrix.orgDWD-Daniel adding a store_path did not change the result. 20:50:30
22 Jun 2021
@aaron:raim.istAaron I'm trying to use https://github.com/russelldavies/matrix-archive which uses nio under the covers. I am getting jsonschema.exceptions.ValidationError: 'sender_claimed_keys' is a required property when trying to import my E2EE keys from Element. Is it an Element bug that it didn't include sender_claimed_keys in the export? or is it a nio bug where that shouldn't be marked as required? 04:15:05
@aaron:raim.istAaron(is there an easy way to decrypt the file manually so I can see what was included?)04:18:37
@realdwd:matrix.orgDWD-Daniel

I've managed to set up the encryption issue i had last night. Now I'm attempting to set up a named Sqlite store. If i do not set one, a default db file is created and the data stored to it. If i do create the store, no data is synced to it. Do I need to manually sync the database?

def async_client_factory() -> AsyncClient:
    store = SqliteStore(
        user_id=user_id,
        device_id=device_id,
        store_path=storage_path,
        database_name='storage.db',
    )

    config = AsyncClientConfig(
        max_limit_exceeded=0,
        max_timeouts=0,
        store_sync_tokens=True,
        encryption_enabled=True,
        store=store,
    )
    client = AsyncClient(
        homeserver=homeserver,
        user=user_id,
        config=config,
    )
    return client


async def main() -> None:
    client: AsyncClient = async_client_factory()

    client.add_event_callback(message_callback, RoomMessageText)
    client.add_response_callback(sync_cb, SyncResponse)

    resp = await client.login(password)
    print('client_id:', client.user_id)

    rooms = await client.joined_rooms()
    if isinstance(rooms, JoinedRoomsResponse):
        print('Connected to rooms:', rooms.rooms)

        for _room in rooms.rooms:
            room = MatrixRoom(
                room_id=_room,
                own_user_id=client.user_id,
                encrypted=True,
            )
            print(' -', room.display_name, room, room.member_count)
    await client.sync_forever(timeout=10000) # milliseconds

asyncio.get_event_loop().run_until_complete(main())
06:09:08
@poljar:matrix.orgpoljar i think the store shouldn't be opened when you pass it as the store parameter, you just pass the class 06:36:39
@poljar:matrix.orgpoljar but you can change the name by passing just the store_name in the AsyncClientConfig 06:37:36
@poljar:matrix.orgpoljar
In reply to @aaron:raim.ist
(is there an easy way to decrypt the file manually so I can see what was included?)
i thinks we should default to an empty list for the sender claimed keys if they aren't included in the export, you can decrypt an export with this method https://github.com/poljar/matrix-nio/blob/master/nio/crypto/key_export.py#L50
06:40:33
@realdwd:matrix.orgDWD-Daniel
In reply to @poljar:matrix.org
i think the store shouldn't be opened when you pass it as the store parameter, you just pass the class
That did it, thank you.
10:39:04
@realdwd:matrix.orgDWD-Daniel I expect the synctokens to help filter the number of events requested by client.sync_forever, which i think it is - between 5 and 8 messages are returned from each of the rooms my account is in. Is there a way to prevent anything prior to that synctoken from being returned so the bot doesn't reprocess anything? Or is reprocess-avoidance left to the user to implement 10:43:49
@poljar:matrix.orgpoljar i think the established technique for this is to call sync() once manually and then register your callbacks and only then call sync_forever() 11:02:29
@realdwd:matrix.orgDWD-Daniel
In reply to @poljar:matrix.org
i think the established technique for this is to call sync() once manually and then register your callbacks and only then call sync_forever()
Thank you, worked a charm.
11:21:47
@realdwd:matrix.orgDWD-Daniel changed their display name from realdwd to DWD-Daniel.21:09:22

There are no newer messages yet.


Back to Room List