Skip to content

Validation errors for PresenceItem #85

@tomballgithub

Description

@tomballgithub

I am using a script that relies on 'xbox-webapi-python', but I noticed that your fork is actually maintained, so I thought I'd bring my issue here.

The issue is that within pythonxbox\api\provider\presence\__init__.py, I am getting errors, even with your code base, of:
1 validation error for PresenceItem devices.0.titles.1.activity Input should be a valid array [type=list_type, input_value={'richPresence': 'The City: The Theater'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/list_type

The line that causes the issues is the last one in get_presence:
return PresenceItem.model_validate_json(resp.text)

I noticed that the response from Xbox does not give an error when it's like this:

{
    'xuid': '2535468411947698',
    'state': 'Online',
    'devices': [{
            'type': 'Scarlett',
            'titles': [{
                    'id': '750323071',
                    'name': 'Home',
                    'placement': 'Background',
                    'state': 'Active',
                    'lastModified': '2026-01-20T22:32:36.7770783'
                }, {
                    'id': '1870487792',
                    'name': 'NBA 2K26',
                    'placement': 'Full',
                    'state': 'Active',
                    'lastModified': '2026-01-20T22:32:36.7770783'
                }
            ]
        }
    ]
}

but it does give an error when it's this:

{
    'xuid': '2535468411947698',
    'state': 'Online',
    'devices': [{
            'type': 'Scarlett',
            'titles': [{
                    'id': '750323071',
                    'name': 'Home',
                    'placement': 'Background',
                    'state': 'Active',
                    'lastModified': '2026-01-20T22:32:36.7770783'
                }, {
                    'id': '1870487792',
                    'activity': {
                        'richPresence': 'The City'
                    },
                    'name': 'NBA 2K26',
                    'placement': 'Full',
                    'state': 'Active',
                    'lastModified': '2026-01-20T22:33:22.3885066'
                }
            ]
        }
    ]
}

The part that is causing the error is this:
'activity': { 'richPresence': 'The City' },

And if I change the last line to the following, removing the 'activity' section, it no longer fails:

        data = resp.json()
        # Iterate through each device
        for device in data.get('devices', []):
            # Iterate through each title in that device
            for title in device.get('titles', []):
                # Remove 'activity' if it exists
                title.pop('activity', None)
        json_string = json.dumps(data)
        return PresenceItem.model_validate_json(json_string)

This page from Microsoft shows a sample PresenceRecord response that includes the 'activity' section:
https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/live/rest/uri/presence/uri-usersmeget

And if I force that exact response into get_presence as follows, it also generates errors for the 'activity' section:

        json_string = """
        {
          "xuid": "0123456789",
          "state": "online",
          "devices": [
            {
              "type": "D",
              "titles": [
                {
                  "id": "12341234",
                  "name": "Contoso 5",
                  "state": "active",
                  "placement": "fill",
                  "timestamp": "2012-09-17T07:15:23.4930000",
                  "activity": {
                    "richPresence": "Team Deathmatch on Nirvana"
                  }
                },
                {
                  "id": "12341235",
                  "name": "Contoso Waypoint",
                  "timestamp": "2012-09-17T07:15:23.4930000",
                  "placement": "snapped",
                  "state": "active",
                  "activity": {
                    "richPresence": "Using radar"
                  }
                }
              ]
            },
            {
              "type": "W8",
              "titles": [
                {
                  "id": "23452345",
                  "name": "Contoso Gamehelp",
                  "state": "active",
                  "placement": "full",
                  "timestamp": "2012-09-17T07:15:23.4930000",
                  "activity": {
                    "richPresence": "Nirvana page"
                  }
                }
              ]
            }
          ]
        }
        """
        return PresenceItem.model_validate_json(json_string)

The errors:

3 validation errors for PresenceItem
devices.0.titles.0.activity
  Input should be a valid array [type=list_type, input_value={'richPresence': 'Team Deathmatch on Nirvana'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/list_type
devices.0.titles.1.activity
  Input should be a valid array [type=list_type, input_value={'richPresence': 'Using radar'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/list_type
devices.1.titles.0.activity
  Input should be a valid array [type=list_type, input_value={'richPresence': 'Nirvana page'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/list_type

And these errors are pydantic not liking something about what should be a valid JSON from Xbox.

How to formally solve?
@tr4nt0r


This repo is using Opire - what does it mean? 👇
💵 Everyone can add rewards for this issue commenting /reward 100 (replace 100 with the amount).
🕵️‍♂️ If someone starts working on this issue to earn the rewards, they can comment /try to let everyone know!
🙌 And when they open the PR, they can comment /claim #85 either in the PR description or in a PR's comment.

🪙 Also, everyone can tip any user commenting /tip 20 @tomballgithub (replace 20 with the amount, and @tomballgithub with the user to tip).

📖 If you want to learn more, check out our documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions