Skip to content

KeyError: 'messages' #7

@Lucasquattro

Description

@Lucasquattro

Hi there,
I tried to run the script but it seems not correcly recognizing the json content for some reason.

Is previously ran into this error and commented out the line 176 as suggested in other discussion:

Traceback (most recent call last):
  File "/Users/luca/Downloads/arbkp/import-master/exp/telegram_import.py", line 240, in <module>
    import_history(
  File "/Users/luca/Downloads/arbkp/import-master/exp/telegram_import.py", line 176, in import_history
    assert data["type"] == "personal_chat"
           ~~~~^^^^^^^^
KeyError: 'type'

But now I'm stucked here, any ideas? Thanks!

Traceback (most recent call last):
  File "/Users/luca/Downloads/arbkp/import-master/exp/telegram_import.py", line 240, in <module>
    import_history(
  File "/Users/luca/Downloads/arbkp/import-master/exp/telegram_import.py", line 179, in import_history
    messages, file_list = convert_to_whatsapp_format(data, only_first_n_messages)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luca/Downloads/arbkp/import-master/exp/telegram_import.py", line 22, in convert_to_whatsapp_format
    df = pandas.DataFrame.from_dict(data["messages"]).sort_values(by=["date"])
                                    ~~~~^^^^^^^^^^^^
KeyError: 'messages'

I'm on macos, python3 on last version, all requirements satisfied and below the example json I'm using:

{
    "about": "Here is the data you requested. Remember: Telegram is ad free, it doesn't use your data for ad targeting and doesn't sell it to others. Telegram only keeps the information it needs to function as a secure and feature-rich cloud service.\n\nCheck out Settings > Privacy & Security on Telegram's mobile apps for the relevant settings.",
    "chats": {
        "about": "This page lists all chats from this export.",
        "list": [
            {
                "name": "testuser",
                "type": "personal_chat",
                "id": 1111111111,
                "messages": [
                    {
                        "id": 740140,
                        "type": "message",
                        "date": "2024-02-06T14:13:29",
                        "date_unixtime": "1707225209",
                        "from": "testuser",
                        "from_id": "user1111111111",
                        "text": "test test",
                        "text_entities": [
                            {
                                "type": "plain",
                                "text": "test test"
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions