DevilXD / TwitchDropsMiner

An app that allows you to AFK mine timed Twitch drops, with automatic drop claiming and channel switching.
MIT License
1.74k stars 169 forks source link

Fatal error when trying to access available streams #526

Closed SuaveIV closed 2 months ago

SuaveIV commented 4 months ago
14:10:06: Fatal error encountered:
14:10:06: 
14:10:06: Traceback (most recent call last):
14:10:06:   File "main.py", line 153, in main
14:10:06:   File "twitch.py", line 570, in run
14:10:06:   File "twitch.py", line 719, in _run
14:10:06:   File "channel.py", line 287, in update_stream
14:10:06:   File "channel.py", line 255, in get_stream
14:10:06: KeyError: 'data'
14:10:06: 
14:10:06: Exiting...
14:10:06: 
14:10:06: Application Terminated.
14:10:06: Close the window to exit the application.
DevilXD commented 4 months ago

Hello.

Yes, I can see it in my miner as well. I'll investigate the cause and report back any findings.

jordyamc commented 4 months ago

I got the same error but from fetch_inventory

11:56:14: Fatal error encountered:
11:56:14: 
11:56:14: Traceback (most recent call last):
11:56:14:   File "main.py", line 153, in main
11:56:14:   File "twitch.py", line 570, in run
11:56:14:   File "twitch.py", line 620, in _run
11:56:14:   File "twitch.py", line 1434, in fetch_inventory
11:56:14: KeyError: 'data'
DevilXD commented 4 months ago

I've just got a similar error (KeyError: data) from 3 different GQL endpoints, but the miner has launched just fine the 4th time. My conclusion is that it's a temporary glitch caused by Twitch doing weird stuff in the background. It seems to be okay now.

jordyamc commented 4 months ago

I printed the response from get_stream and some of the response got an error

12:49:13: {'data': {'user': {'id': '93079282', 'profileURL': 'https://www.twitch.tv/tdbags', 'displayName': 'TDbags', 'login': 'tdbags', 'profileImageURL': 'https://static-cdn.jtvnw.net/jtv_user_pictures/887c0e6a-092a-4f84-9310-201b7d7a7234-profile_image-150x150.png', 'broadcastSettings': {'id': '93079282', 'title': 'The first desce1ndant Freyna main - visioni di mod', 'game': {'id': '2104758320', 'displayName': 'The First Descendant', 'name': 'The First Descendant', '__typename': 'Game'}, '__typename': 'BroadcastSettings'}, 'stream': None, '__typename': 'User'}}, 'extensions': {'durationMilliseconds': 57, 'operationName': 'VideoPlayerStreamInfoOverlayChannel', 'requestID': '01J4A6SCSN2X9GG2VG6EKASKM4'}}
12:49:13: {'data': {'user': {'id': '420048216', 'profileURL': 'https://www.twitch.tv/brutalles', 'displayName': 'brutalles', 'login': 'brutalles', 'profileImageURL': 'https://static-cdn.jtvnw.net/jtv_user_pictures/9bbebd85-fea8-470a-934e-6a6926af880e-profile_image-150x150.png', 'broadcastSettings': {'id': '420048216', 'title': 'WOW NOW ! More Games Later!', 'game': {'id': '18122', 'displayName': 'World of Warcraft', 'name': 'World of Warcraft', '__typename': 'Game'}, '__typename': 'BroadcastSettings'}, 'stream': None, '__typename': 'User'}}, 'extensions': {'durationMilliseconds': 59, 'operationName': 'VideoPlayerStreamInfoOverlayChannel', 'requestID': '01J4A6SCSNVSKB57YYZYR0YBK5'}}
12:49:13: {'data': {'user': {'id': '45624285', 'profileURL': 'https://www.twitch.tv/snowwolfess', 'displayName': 'Snowwolfess', 'login': 'snowwolfess', 'profileImageURL': 'https://static-cdn.jtvnw.net/jtv_user_pictures/93ed3346-2a76-40df-a444-96e172605824-profile_image-150x150.png', 'broadcastSettings': {'id': '45624285', 'title': "[18+] 5 streak in the bag now to farm acid and silos '.'  |  !govee | !TFD !KW🐺#ad #contentcreator", 'game': {'id': '1441208453', 'displayName': 'Once Human', 'name': 'Once Human', '__typename': 'Game'}, '__typename': 'BroadcastSettings'}, 'stream': None, '__typename': 'User'}}, 'extensions': {'durationMilliseconds': 62, 'operationName': 'VideoPlayerStreamInfoOverlayChannel', 'requestID': '01J4A6SCSK8A790G2CR3JVBPRR'}}
12:49:13: {'error': 'Unauthorized', 'status': 401, 'message': 'The "Authorization" token is invalid.'}
12:49:14: {'data': {'user': {'id': '21646144', 'profileURL': 'https://www.twitch.tv/angelysaras', 'displayName': 'angelysaras', 'login': 'angelysaras', 'profileImageURL': 'https://static-cdn.jtvnw.net/jtv_user_pictures/angelysaras-profile_image-cd97d66efa250999-150x150.png', 'broadcastSettings': {'id': '21646144', 'title': 'ES MI CUMPLE VAMOOO MARVEL RIVALS PS5 / CODIGO ANGELYSARAS EN LA TIENDA !twitchquest !skin !bebida !config !meta', 'game': {'id': '1264310518', 'displayName': 'Marvel Rivals', 'name': 'Marvel Rivals', '__typename': 'Game'}, '__typename': 'BroadcastSettings'}, 'stream': None, '__typename': 'User'}}, 'extensions': {'durationMilliseconds': 57, 'operationName': 'VideoPlayerStreamInfoOverlayChannel', 'requestID': '01J4A6SCWKNJ3N26MW8432TFQ1'}}
12:49:14: {'data': {'user': {'id': '147084863', 'profileURL': 'https://www.twitch.tv/ewc_pt2', 'displayName': 'EWC_PT2', 'login': 'ewc_pt2', 'profileImageURL': 'https://static-cdn.jtvnw.net/jtv_user_pictures/5140a406-d46a-42c9-ab5b-161a1a34e146-profile_image-150x150.png', 'broadcastSettings': {'id': '147084863', 'title': 'Team BDS vs. FaZe Clan - EWC R6 // Dia 3 - Quartas de Final', 'game': {'id': '460630', 'displayName': "Tom Clancy's Rainbow Six Siege", 'name': "Tom Clancy's Rainbow Six Siege", '__typename': 'Game'}, '__typename': 'BroadcastSettings'}, 'stream': {'id': '42689844808', 'viewersCount': 136, 'tags': [], '__typename': 'Stream'}, '__typename': 'User'}}, 'extensions': {'durationMilliseconds': 58, 'operationName': 'VideoPlayerStreamInfoOverlayChannel', 'requestID': '01J4A6SCWMGE09XGAFF8235R1V'}}
12:49:14: {'error': 'Unauthorized', 'status': 401, 'message': 'The "Authorization" token is invalid.'}
12:49:14: {'data': {'user': {'id': '514644142', 'profileURL': 'https://www.twitch.tv/ali3nsun', 'displayName': 'Ali3nSun', 'login': 'ali3nsun', 'profileImageURL': 'https://static-cdn.jtvnw.net/jtv_user_pictures/6c06fc3a-3f8c-458d-a82b-b1e9bcd27378-profile_image-150x150.png', 'broadcastSettings': {'id': '514644142', 'title': '⛱️ SUMMER UPDATE PARTY 🍦 Viessa DPS bananas 👙 !code !wishlist !merch💜 #NexonCreator @ali3nsun !socials', 'game': {'id': '2104758320', 'displayName': 'The First Descendant', 'name': 'The First Descendant', '__typename': 'Game'}, '__typename': 'BroadcastSettings'}, 'stream': None, '__typename': 'User'}}, 'extensions': {'durationMilliseconds': 59, 'operationName': 'VideoPlayerStreamInfoOverlayChannel', 'requestID': '01J4A6SCX3SR2N26G3CVTMJ1AT'}}
DevilXD commented 4 months ago

It has crashed again for me just now.

Unauthorized, huh? Well, there's two things I can deduce from this then:

• GQL calls should be handling the "error" field, in addition to the "errors" field. I'm assuming that it's Twitch doing some magic in the GQL, to make it return a response when no response could be returned, but still, it's just a matter of including handling for that as well. • I don't know what has happened to Twitch's authorization portion of their server, but it's clearly not working as good as it should be. If the token would really be invalid, then all requests would return these errors, yet only some of them do, and most of them pass correctly.

For now, I can add the "error" field handling, but there's no real way to tell if that unauthorized error is legit or not, so the miner is going to crash anyway, albeit with a more helpful error message instead.

EDIT/PS: According to the id.twitch.tv/oauth2/validate endpoint, my authorization token cannot expire, as expires_in value is returned as 0. Seems like it really is just Twitch servers struggling a bit.

DevilXD commented 4 months ago

https://github.com/DevilXD/TwitchDropsMiner/commit/9779d7a2c8f2e5e72a16fbf0094142c932f9f796 implements a way to detect the "error" key being present in GQL responses, leading to a more helpful error message.

matarife123 commented 4 months ago

9779d7a implements a way to detect the "error" key being present in GQL responses, leading to a more helpful error message.

Could you upload the zip file please?

guihkx commented 4 months ago

9779d7a implements a way to detect the "error" key being present in GQL responses, leading to a more helpful error message.

Thanks. I'm not sure if this is helpful, but in my case, the error seems intermittent, even after re-authentication:

17:29:04: Please log in to continue.
17:29:09: Enter this code on the Twitch's device activation page: ZFYEGLJX
17:29:32: Fatal error encountered:
17:29:32: 
17:29:32: Traceback (most recent call last):
17:29:32:   File "/home/gui/dev/TwitchDropsMiner/channel.py", line 250, in get_stream
17:29:32:     response: JsonType = await self._twitch.gql_request(
17:29:32:                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:29:32:   File "/home/gui/dev/TwitchDropsMiner/twitch.py", line 1354, in gql_request
17:29:32:     raise MinerException(
17:29:32: exceptions.MinerException: GQL error: Unauthorized: The "Authorization" token is invalid.
17:29:32: 
17:29:32: The above exception was the direct cause of the following exception:
17:29:32: 
17:29:32: Traceback (most recent call last):
17:29:32:   File "/home/gui/dev/TwitchDropsMiner/main.py", line 153, in main
17:29:32:     await client.run()
17:29:32:   File "/home/gui/dev/TwitchDropsMiner/twitch.py", line 570, in run
17:29:32:     await self._run()
17:29:32:   File "/home/gui/dev/TwitchDropsMiner/twitch.py", line 719, in _run
17:29:32:     await asyncio.gather(
17:29:32:   File "/home/gui/dev/TwitchDropsMiner/channel.py", line 287, in update_stream
17:29:32:     self._stream = await self.get_stream()
17:29:32:                    ^^^^^^^^^^^^^^^^^^^^^^^
17:29:32:   File "/home/gui/dev/TwitchDropsMiner/channel.py", line 254, in get_stream
17:29:32:     raise MinerException(f"Channel: {self._login}") from exc
17:29:32: exceptions.MinerException: Channel: simuverserden
17:29:32: 
17:29:32: Exiting...
17:29:33: 
17:29:33: Application Terminated.
17:29:33: Close the window to exit the application.

P.S.: The "upload job" of commit 9779d7a2c8f2e5e72a16fbf0094142c932f9f796 randomly failed, so you might want to re-trigger it.

DevilXD commented 4 months ago

Could you upload the zip file please?

@matarife123 I've re-triggered the workflow, so you can just grab the latest dev build. Still, this isn't "a fix" any more than a mere "more helpful error message" being printed out, instead of a confusing error it was before. It'll still crash, in the very same place it'd crash on the previous dev build.

Again, I don't know what I'm supposed to fix here, as the authentication token still works, Twitch just fails to process it sometimes. This has started happening only 2 hours ago, so I'd imagine it'll pass on it's own, once Twitch fixes the issue on their end.

DeadlyShadow71 commented 4 months ago

`23:05:00: Fatal error encountered: 23:05:00: 23:05:00: Traceback (most recent call last): 23:05:00: File "channel.py", line 250, in get_stream 23:05:00: File "twitch.py", line 1354, in gql_request 23:05:00: exceptions.MinerException: GQL error: Unauthorized: The "Authorization" token is invalid. 23:05:00: 23:05:00: The above exception was the direct cause of the following exception: 23:05:00: 23:05:00: Traceback (most recent call last): 23:05:00: File "main.py", line 153, in main 23:05:00: File "twitch.py", line 570, in run 23:05:00: File "twitch.py", line 719, in _run 23:05:00: File "channel.py", line 287, in update_stream 23:05:00: File "channel.py", line 254, in get_stream 23:05:00: exceptions.MinerException: Channel: pablokilo 23:05:00: 23:05:00: Exiting... 23:05:00: 23:05:00: Application Terminated. 23:05:00: Close the window to exit the application.

`

It's still broken, even with the new files, guess we'll see if Twitch does anything or not.

Artanisx commented 4 months ago

Adding my output as well:

10:31:35: Fatal error encountered:
10:31:35: 
10:31:35: Traceback (most recent call last):
10:31:35:   File "main.py", line 160, in main
10:31:35:   File "twitch.py", line 772, in run
10:31:35:   File "twitch.py", line 817, in _run
10:31:35:   File "twitch.py", line 1670, in fetch_inventory
10:31:35:   File "asyncio\tasks.py", line 571, in _wait_for_one
10:31:35:   File "twitch.py", line 1608, in fetch_campaigns
10:31:35:   File "twitch.py", line 1575, in gql_request
10:31:35: exceptions.MinerException: GQL error: [{'message': 'PersistedQueryNotFound'}]
10:31:35: 
10:31:35: Exiting...
10:31:36: 
10:31:36: Application Terminated.
10:31:36: Close the window to exit the application.
DevilXD commented 4 months ago

@Artanisx That's an entirely different error, that has nothing to do with this issue. Before you report anything here, make sure it's actually the same issue you're experiencing. New issues have to be filed separately.

Btw, that has been fixed over 2 weeks ago by https://github.com/DevilXD/TwitchDropsMiner/commit/0f3a7841b7a99a53ddb9186e2ffc8ef2c18e332d, so you're most likely using an outdated miner version.

Artanisx commented 4 months ago

@Artanisx That's an entirely different error, that has nothing to do with this issue. Before you report anything here, make sure it's actually the same issue you're experiencing. New issues have to be filed separately.

Btw, that has been fixed over 2 weeks ago by 0f3a784, so you're most likely using an outdated miner version.

Thanks. Sorry for the mistake, also I wasn't aware of a new version as Github says the last one was released on December 2022 and the last dev one is marked May 19, 2023. I only now realized the "Last build date: 2024-08-02 20:41:45+00:00" message inside. Going to update now!

EDIT: I can confirm my off-topic issue is indeed fixed, thanks :)

Artanisx commented 4 months ago

OK, this time I'm indeed getting the same error of this thread https://github.com/DevilXD/TwitchDropsMiner/issues/526#issuecomment-2266147090:

12:13:16: Fatal error encountered:
12:13:16: 
12:13:16: Traceback (most recent call last):
12:13:16:   File "channel.py", line 250, in get_stream
12:13:16:   File "twitch.py", line 1354, in gql_request
12:13:16: exceptions.MinerException: GQL error: Unauthorized: The "Authorization" token is invalid.
12:13:16: 
12:13:16: The above exception was the direct cause of the following exception:
12:13:16: 
12:13:16: Traceback (most recent call last):
12:13:16:   File "main.py", line 153, in main
12:13:16:   File "twitch.py", line 570, in run
12:13:16:   File "twitch.py", line 719, in _run
12:13:16:   File "channel.py", line 287, in update_stream
12:13:16:   File "channel.py", line 254, in get_stream
12:13:16: exceptions.MinerException: Channel: amiomia
12:13:16: 
12:13:16: Exiting...
12:13:16: 
12:13:16: Application Terminated.
12:13:16: Close the window to exit the application.

:)

avdichiara commented 4 months ago

It would be nice if there was a way to automatically restart the application when a fatal error like this occurs

Luckz commented 4 months ago

Since this started happening, I haven't even been able to get past startup at all. Not on my account, not on my friend's. (And a fresh login doesn't change anything.)

DevilXD commented 4 months ago

I'm really not sure what to do here, this issue has passed for me yesterday, and didn't crash since. I'm not able to reproduce it anymore. Fresh login won't change anything, as the authorization key does not expire, and thus the application will receive the very same one it had before re-logging. The only way to change the authorization token, is to change your Twitch account password.

If _get_stream crashing is the main culprit here, I could wrap it in a task, so that even if it crashes, "the worst" that can happen, is a channel not being marked as ONLINE. The viewers count update from the websocket should then nudge it towards another refresh within a few minutes. The downside of this is that it'd hide other potential issues that could cause stream fetching to not work later on, but it'd work as a "for now" bandaid fix. Fun fact, it already runs in a task when the PENDING_ONLINE status is in progress, as that's the only way a channel can change it's status once the mining starts - only the initial channel gather operation after a reload can actually catch any issues with stream-fetching that'd arise.

@avdichiara Auto-restart has already been suggested before, and the answer is still no. If you'd like to learn why, you can search the already closed issues for an explanation.

DeadlyShadow71 commented 4 months ago

I think the problem was on twitch's side of things, as I am able to mine again, not sure how long it has been since it works again but it works now, grateful enough for that. I think you can close this issue since it wasn't related to something you could fix yourself, afaik.

biast12 commented 4 months ago

i just deleted all the cookies, lock and cache files and logged in again and now it works, i'll report back if it breaks

gibbed commented 4 months ago

I would say leave this open until long enough has passed with no reports. I'm still getting unauthorized infrequently.

Luckz commented 4 months ago

If _get_stream crashing is the main culprit here, I could wrap it in a task, so that even if it crashes, "the worst" that can happen, is a channel not being marked as ONLINE. The viewers count update from the websocket should then nudge it towards another refresh within a few minutes. The downside of this is that it'd hide other potential issues that could cause stream fetching to not work later on, but it'd work as a "for now" bandaid fix. Fun fact, it already runs in a task when the PENDING_ONLINE status is in progress, as that's the only way a channel can change it's status once the mining starts - only the initial channel gather operation after a reload can actually catch any issues with stream-fetching that'd arise.

Maybe that functionality should be hidden behind a launch parameter, to indeed only be used when the user specifically needs a band-aid? I was able to idle for one hour earlier, and then it started crashing again and now I'm at 15+ unsuccessful start attempts.

P.S.: It doesn't immediately crash when I tick Priority Only. I've tried excluding game based on channel names in the crashes, but they're actually fairly often streamers that aren't even online at the moment (I excluded STALCRAFT: X, XDefiant, Path of Exile, EVE Online, Overwatch 2 and from then on my crashes didn't have channel names anymore and just complained about the authorization. EVE and PoE don't even have drop campaigns, but they were games played or last-played by the channel names I saw.)

It still crashes quickly on Priority, but I do get to idle for a few minutes.

DevilXD commented 4 months ago

Maybe that functionality should be hidden behind a launch parameter

Hmmmmm. I actually kinda like that idea. Like, I'd prefer to know that something bad is happening, but at the same time, have the ability to just tell the miner to "deal with it". There would have to be some additional code to deal with the missing information, but for some portions of the miner, it'd be doable.

I'll think about it overnight, and see what I can come up with tomorrow.

secretsoup commented 4 months ago

I had this issue today as well still going on with the Authorization token problem.

Clearing cookies, lock and cache fixed it for a bit but then it re-triggered again as soon as I added a new game to my list. Closing and re-opening seemed to fix it after a few tries. I'm using v16.dev.9779d7a

Marcellse commented 4 months ago

I also had this problem v16.dev.9779d7a

zsnzzg commented 4 months ago
22:14:38: 正在观看: 國濤
22:23:46: 观看直播获得积分:  50, 总积分: 490
22:23:46: 观看直播获得积分:  50, 总积分: 1070
22:23:46: 观看直播获得积分:  50, 总积分: 110
22:23:46: 观看直播获得积分:  50, 总积分: 110
22:23:46: 观看直播获得积分:  50, 总积分: 110
22:36:40: ERROR: Exception in process_notifications task
22:36:40: Traceback (most recent call last):
22:36:40:   File "O:\zsn\TDM\TwitchDropsMiner\utils.py", line 142, in wrapper
22:36:40:     await afunc(*args, **kwargs)
22:36:40:   File "O:\zsn\TDM\TwitchDropsMiner\twitch.py", line 1194, in process_notifications
22:36:40:     await self.gql_request(
22:36:40:   File "O:\zsn\TDM\TwitchDropsMiner\twitch.py", line 1362, in gql_request
22:36:40:     raise GQLException(
22:36:40: exceptions.GQLException: Unauthorized: The "Authorization" token is invalid.
22:36:52: Fatal error encountered:
22:36:52: 
22:36:52: Traceback (most recent call last):
22:36:52:   File "O:\zsn\TDM\TwitchDropsMiner\twitch.py", line 1545, in get_live_streams
22:36:52:     response = await self.gql_request(
22:36:52:   File "O:\zsn\TDM\TwitchDropsMiner\twitch.py", line 1362, in gql_request
22:36:52:     raise GQLException(
22:36:52: exceptions.GQLException: Unauthorized: The "Authorization" token is invalid.
22:36:52: 
22:36:52: The above exception was the direct cause of the following exception:
22:36:52: 
22:36:52: Traceback (most recent call last):
22:36:52:   File "O:\zsn\TDM\TwitchDropsMiner\main.py", line 153, in main
22:36:52:     await client.run()
22:36:52:   File "O:\zsn\TDM\TwitchDropsMiner\twitch.py", line 572, in run
22:36:52:     await self._run()
22:36:52:   File "O:\zsn\TDM\TwitchDropsMiner\twitch.py", line 730, in _run
22:36:52:     new_channels.update(await self.get_live_streams(game))
22:36:52:   File "O:\zsn\TDM\TwitchDropsMiner\twitch.py", line 1556, in get_live_streams
22:36:52:     raise MinerException(f"Game: {game.slug}") from exc
22:36:52: exceptions.MinerException: Game: naraka-bladepoint
22:36:52: 
22:36:52: 正在退出...
22:36:53: 
22:36:53: 应用程序已终止,请关闭窗口以退出应用程序。

still error b20f98d

biast12 commented 4 months ago

i just deleted all the cookies, lock and cache files and logged in again and now it works, i'll report back if it breaks

turn on my PC this morning and now got the error again

DevilXD commented 4 months ago

I've decided to, in the end, just add the extra handling without any additional launch arguments, mostly because I couldn't come up with a good name for said argument lol

https://github.com/DevilXD/TwitchDropsMiner/commit/b20f98da7a72ddca20eb462229faf330026b3511 implements the changes. I'd like to note that this does not resolve the problem, merely silences the two main sources where this error can happen (mass stream refresh on reload, and GQL drop progress query after every watch request is sent), which leaves other GQL requests untouched. Hopefully other requests won't ever crash, or will be doing so infrequently enough to make this issue bearable.

DevilXD commented 4 months ago

Hmm, well, while it does help, it doesn't solve everything:

Fatal error encountered:
20:08:18: 
20:08:18: Traceback (most recent call last):
20:08:18:   File "main.py", line 153, in main
20:08:18:   File "twitch.py", line 572, in run
20:08:18:   File "twitch.py", line 622, in _run
20:08:18:   File "twitch.py", line 1442, in fetch_inventory
20:08:18:   File "asyncio\tasks.py", line 619, in _wait_for_one
20:08:18:   File "twitch.py", line 1397, in fetch_campaigns
20:08:18:   File "twitch.py", line 1362, in gql_request
20:08:18: exceptions.GQLException: Unauthorized: The "Authorization" token is invalid.

Fetching campaigns isn't something that can be skipped on. More research is needed to deal with this issue, which I'll be doing over the next couple of days.

Nazar1ky commented 4 months ago

Hello! I did some research, and investigate how work Twitch-Channel-Points-Miner-v2. That miner doesn't have any issues, because it use Smart TV client_id - Reference. As I see Twitch Drops Miner use Android WEB client_id. But... if miner will use Smart TV client_id campaigns GraphQL endpoint won't return campaigns: (see dropCampaigns)

{
  'currentUser': {
    'id': '',
    'login': '',
    'dropCampaigns': None,
    '__typename': 'User'
  },
  'rewardCampaignsAvailableToUser': [
    {
      ...
    }
  ]
}

Update: Android App client_id (Not Android WEB) works fine! (https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/master/TwitchChannelPointsMiner/constants.py#L11)

DevilXD commented 4 months ago

Hmm, interesting. It may be more worthwhile to switch back to the android app again. Last time this miner was using it, they've made the login flow use their integrity system. Hopefully it's not the case anymore.

Nazar1ky commented 4 months ago

I have sent PR, accept it if you want this client.

DevilXD commented 4 months ago

An alternative solution would be to just retry the failed requests. I've been testing a proof-of-concept retry loop when this error happens, and in all cases so far, if the first request failed, the second one succeeded.

Nazar1ky commented 4 months ago

An alternative solution would be to just retry the failed requests. I've been testing a proof-of-concept retry loop when this error happens, and in all cases so far, if the first request failed, the second one succeeded.

Errors happen's very often as I know, but you can try what solution fit better

DevilXD commented 4 months ago

After further research on the subject, it seems like Twitch has implemented a rate limit on the amount of GQL requests one can send at one time. The miner tends to be quite efficient with those, except in a particular case - when setting channels online right after a reload, which is exactly what is causing the problems. My current test case has tried to set 343 channels online at once, resulting in 343 separate GQL requests being send at once, and 50 of those bouncing back as "Unauthorized". It could be the case where Twitch has implemented a local rate-limit on GQL access in their web client, and anyone other accessing GQL faster than intended will be "shooed away" with "Unauthorized" errors.

This is all just speculation, but if true, the fix is quite simple - just implement a local rate limit in the miner. This should hopefully resolve this issue, and we can go back to the state from before the dirty fixes that were applied here.

Besides a rate limiter, I can also optimize the operation of setting all channels online on reload, since GQL can actually take in a batch of up to 20 operations at once. That'd reduce the GQL "hammering" from 343 separate requests, down to only 18. Should be much more manageable. Campaign details are already fetched in batches like that, and it works perfectly there.

I'll be working on this over the next upcoming days.

gibbed commented 4 months ago

After further research on the subject, it seems like Twitch has implemented a rate limit on the amount of GQL requests one can send at one time.

Hah! I suspected this might be the issue but hadn't looked into it further to the point where I wanted to bring it up here yet.

gibbed commented 4 months ago

Looks like a new one has popped up: websocket is giving me ERR_BADAUTH now right off the bat with a legit token, in addition to rejecting the first GQL request with The "Authorization" token is invalid..

20:12:50: DEBUG: Websocket[0] received: WSMessage(type=<WSMsgType.TEXT: 1>, data='{"type":"RESPONSE","error":"ERR_BADAUTH","nonce":"CENSORED"}\r\n', extra='')

Are they rejecting tokens now that are getting generated at /activate for the miner?

N1Hawk commented 3 months ago

Looks like a new one has popped up: websocket is giving me ERR_BADAUTH now right off the bat with a legit token, in addition to rejecting the first GQL request with The "Authorization" token is invalid..

20:12:50: DEBUG: Websocket[0] received: WSMessage(type=<WSMsgType.TEXT: 1>, data='{"type":"RESPONSE","error":"ERR_BADAUTH","nonce":"CENSORED"}\r\n', extra='')

Are they rejecting tokens now that are getting generated at /activate for the miner?

he knows about this error its been reported and he's working on a patch for it now

gibbed commented 3 months ago

he knows about this error its been reported and he's working on a patch for it now

This is different behavior than to what was previously reported, which is why I posted about it.

woctezuma commented 3 months ago

in addition to rejecting the first GQL request with The "Authorization" token is invalid..

You may want to try:

I have encountered zero error after using this one-line change.

fappyhrc commented 3 months ago

18:46:21: Fatal error encountered: 18:46:21: 18:46:21: Traceback (most recent call last): 18:46:21: File "main.py", line 153, in main 18:46:21: File "twitch.py", line 570, in run 18:46:21: File "twitch.py", line 620, in _run 18:46:21: File "twitch.py", line 1402, in fetch_inventory 18:46:21: KeyError: 'data' 18:46:21: 18:46:21: 正在退出... 18:46:22: 18:46:22: 应用程序已终止,请关闭窗口以退出应用程序。

have you solved it?this is the log

Nazar1ky commented 3 months ago

have you solved it?this is the log

Hey! You can try version here: https://github.com/Windows200000/TwitchDropsMiner-updated/releases/tag/v15.8.1

Emiliaaah commented 3 months ago

I'm not quite sure if my problem is linked to this issue, I was getting the following error:

13:16:54: Fatal error encountered:
13:16:54: 
13:16:54: Traceback (most recent call last):
13:16:54:   File "main.py", line 153, in main
13:16:54:   File "twitch.py", line 572, in run
13:16:54:   File "twitch.py", line 622, in _run
13:16:54:   File "twitch.py", line 1415, in fetch_inventory
13:16:54:   File "twitch.py", line 1362, in gql_request
13:16:54: exceptions.GQLException: Unauthorized: The "Authorization" token is invalid.
13:16:54: 
13:16:54: Exiting...
13:16:54: 
13:16:54: Application Terminated.
13:16:54: Close the window to exit the application.

Hey! You can try version here: https://github.com/Windows200000/TwitchDropsMiner-updated/releases/tag/v15.8.1

The version you linked seems to have fixed my issue though!

N1Hawk commented 3 months ago

have you solved it? this is the log

Hey! You can try version here: https://github.com/Windows200000/TwitchDropsMiner-updated/releases/tag/v15.8.1

this version also worked for me until DevilXD fixes his, its working right now! guys download this!

FlamingFox911 commented 3 months ago

Can confirm, the tagged build does work. ~However, there is a slight bug where Excluded items are not filtered out of the dropdown list. Other than that, it works for now.~

EDIT: It was working for a while, and then:

12:37:19: Please log in to continue.
12:37:22: Enter this code on the Twitch's device activation page: ________
12:37:55: Watching: ______
12:38:06: Progress: ...
...
14:39:29: Fatal error encountered:
14:39:29: 
14:39:29: Traceback (most recent call last):
14:39:29:   File "twitch.py", line 1736, in get_live_streams
14:39:29:   File "twitch.py", line 1575, in gql_request
14:39:29: exceptions.MinerException: GQL error: [{'message': 'PersistedQueryNotFound'}]
14:39:29: 
14:39:29: The above exception was the direct cause of the following exception:
14:39:29: 
14:39:29: Traceback (most recent call last):
14:39:29:   File "main.py", line 160, in main
14:39:29:   File "twitch.py", line 772, in run
14:39:29:   File "twitch.py", line 923, in _run
14:39:29:   File "twitch.py", line 1747, in get_live_streams
14:39:29: exceptions.MinerException: Game: ______
14:39:29: 
14:39:29: Exiting...
14:39:29: 
14:39:29: Application Terminated.
14:39:29: Close the window to exit the application.

EDIT 2: Stable and fixed as of https://github.com/DevilXD/TwitchDropsMiner/commit/f705cc1527e806bb979df9e0dbd077d93728160c

Nazar1ky commented 3 months ago

EDIT: It was working for a while, and then:

Hello! Pull requests has been submitted:

chicken647 commented 3 months ago

9779d7a implements a way to detect the "error" key being present in GQL responses, leading to a more helpful error message.

Could you upload the zip file please?

building the application from source is quite straightforward! this guide: Setting-up-the-environment,-building-and-running

woctezuma commented 3 months ago

building the application from source is quite straightforward!

It may be even simpler to run as a Python script.

DevilXD commented 2 months ago

I guess this can be closed, as the issue isn't happening anymore, and a new bulk-channel-refresh logic has just been implemented, that should help avoid running into similar issues again.