Teekeks / pyTwitchAPI

A Python 3.7 compatible implementation of the Twitch API, EventSub, PubSub and Chat
https://pytwitchapi.dev
MIT License
256 stars 38 forks source link

Internal error while parsing EventSub Prediction event #312

Closed VGorku closed 4 months ago

VGorku commented 5 months ago

Subscriptions and two simple callbacks:

async def test_event(data: ChannelPredictionEvent):
    print('EVENT', data.event.broadcaster_user_id)

async def test_end_event(data: ChannelPredictionEndEvent):
    print('EVENT', data.event.broadcaster_user_id)

subscription_ids['begin'] = await eventsub.listen_channel_prediction_begin(subscription_row['twitch_id'], test_event)
subscription_ids['end'] = await eventsub.listen_channel_prediction_end(subscription_row['twitch_id'], test_end_event)
subscription_ids['lock'] = await eventsub.listen_channel_prediction_lock(subscription_row['twitch_id'], test_event)

What I did is that simply created Prediction on Twitch (everything was fine) and closed submissions right after that. Seems like it's failed upon parsing the Lock event https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelpredictionlock

Sorry for the screenshot, that's all I got for now image

Any suggestions on how to fix that? Thanks <3

VGorku commented 5 months ago

I think I got it.

I was testing off-stream, basically starting Predictions and ending them without any vote. It seems that current implementation does not expect data['event']['outcomes']['top_predictors'] to be empty list: image

Here is my disgusting workaround in twitchAPI/eventsub/webhook.py if someone interested (I dont need top predictors for my project) image

Hope this will be fixed 🤞

Teekeks commented 5 months ago

I cant reproduce this by starting a prediction & then either letting it run out or closing it manually without anyone voting.

Could you please provide the following for further investigation:

Gregorein commented 4 months ago

@Teekeks, I think this may be related to my issue, as I'm also having problems with TopPredictors being handled incorrectly in a prediction.end event

However issue occurs in websocket, not webhooks

https://github.com/Teekeks/pyTwitchAPI/issues/315

Teekeks commented 4 months ago

Fix for this is now available on pypi in v4.2.1. Was not able to reproduce because I already fixed that locally...