Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect to Twitch #386

Closed
daeeros opened this issue Dec 12, 2023 · 29 comments
Closed

Cannot connect to Twitch #386

daeeros opened this issue Dec 12, 2023 · 29 comments
Labels
Bug Something isn't working Solved This issue has been resolved

Comments

@daeeros
Copy link

daeeros commented Dec 12, 2023

image

I use vds amazon ec2 free tier, (Windows Server 2022) with the help of browser authorization opens and tweetch site works, but with the help of the program writes that can not connect, what is the problem and how can it be fixed?

@Suz1e
Copy link
Contributor

Suz1e commented Dec 12, 2023

You need to enter the proxy address on the settings page, usually in the format http://127.0.0.1:port number

@Medicxx2
Copy link

I have same problem (Win10 pro 64bit).

@daeeros
Copy link
Author

daeeros commented Dec 12, 2023

I found the solution to the problem, it was in SSL certificates, for some reason aiohttp could not find and use them, in the file twitch.py on line 662 change:

this:
connector = aiohttp.TCPConnector(limit=50)

to this:
connector = aiohttp.TCPConnector(verify_ssl=False, limit=50)

@xddd121
Copy link

xddd121 commented Dec 12, 2023

brother where is the twitch.py

@daeeros
Copy link
Author

daeeros commented Dec 12, 2023

brother where is the twitch.py

Do not use compiled version, download github source, and run it from python manual.

@xddd121
Copy link

xddd121 commented Dec 12, 2023

If you know how to install can you write dc
dc_nick: time_thief.

@xddd121
Copy link

xddd121 commented Dec 12, 2023

Do you know where the source codes are?

@CDeLeon94
Copy link

Big green button on the home page:
Then either download zip
or grab the URL to use git clone <<Repo>> (Just click the link I provided for now)

@xddd121
Copy link

xddd121 commented Dec 12, 2023

@CDeLeon94 There is no exe file in the dist folder

@Medicxx2
Copy link

I found the solution to the problem, it was in SSL certificates, for some reason aiohttp could not find and use them, in the file twitch.py on line 662 change:

this: connector = aiohttp.TCPConnector(limit=50)

to this: connector = aiohttp.TCPConnector(verify_ssl=False, limit=50)

It works, thanks.

@DevilXD
Copy link
Owner

DevilXD commented Dec 12, 2023

verify_ssl=False is as good as solution to the problem here, as opening a window by breaking the glass. Read - it's not good.

The SSL verification error is masked by the request retry logic. To see it, one would need to disable the exception handling on requests, here:

except (aiohttp.ClientConnectionError, asyncio.TimeoutError):

Changing this to an unrelated exception, like except AssertionError: will let the SSL error be printed out to the output window. Only with that traceback, I may be able to figure out what's wrong here. Without it, not so much.

@DevilXD DevilXD added the Bug Something isn't working label Dec 12, 2023
@Medicxx2
Copy link

Changing this to an unrelated exception, like except AssertionError: will let the SSL error be printed out to the output window. Only with that traceback, I may be able to figure out what's wrong here. Without it, not so much.

12:49:30: Fatal error encountered:
12:49:30:
12:49:30: Traceback (most recent call last):
12:49:30: File "aiohttp\connector.py", line 992, in _wrap_create_connection
12:49:30: File "asyncio\base_events.py", line 1146, in create_connection
12:49:30: File "asyncio\base_events.py", line 1179, in _create_connection_transport
12:49:30: File "asyncio\sslproto.py", line 575, in _on_handshake_complete
12:49:30: File "asyncio\sslproto.py", line 557, in _do_handshake
12:49:30: File "ssl.py", line 917, in do_handshake
12:49:30: ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)
12:49:30:
12:49:30: The above exception was the direct cause of the following exception:
12:49:30:
12:49:30: Traceback (most recent call last):
12:49:30: File "main.py", line 158, in main
12:49:30: File "twitch.py", line 764, in run
12:49:30: File "twitch.py", line 783, in _run
12:49:30: File "twitch.py", line 1469, in get_auth
12:49:30: File "twitch.py", line 515, in validate
12:49:30: File "twitch.py", line 524, in _validate
12:49:30: File "contextlib.py", line 210, in aenter
12:49:30: File "twitch.py", line 1494, in request
12:49:30: File "gui.py", line 2050, in coro_unless_closed
12:49:30: File "aiohttp\client.py", line 1174, in throw
12:49:30: File "aiohttp\client.py", line 574, in _request
12:49:30: File "aiohttp\connector.py", line 544, in connect
12:49:30: File "aiohttp\connector.py", line 911, in _create_connection
12:49:30: File "aiohttp\connector.py", line 1235, in _create_direct_connection
12:49:30: File "aiohttp\connector.py", line 1204, in _create_direct_connection
12:49:30: File "aiohttp\connector.py", line 994, in _wrap_create_connection
12:49:30: aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host m.twitch.tv:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')]
12:49:30:
12:49:30: Exiting...
12:49:30:
12:49:30: Application Terminated.
12:49:30: Close the window to exit the application.

@DevilXD
Copy link
Owner

DevilXD commented Dec 13, 2023

unable to get local issuer certificate

https://www.howtouselinux.com/post/exploring-unable-to-get-local-issuer-certificate

In other words, this is an issue with your machine, mostly. Here's some more resources on this topic:

aio-libs/aiohttp#7287
aio-libs/aiohttp#5375

Based on this information, it seems like something went wrong when you were installing Python. Reinstalling it may solve the problem. Alternatively, one can perform a disk error check / system integrity verification, via chkdsk or a tool I made for this same purpose.

@Vadson159
Copy link

I have the same issue, same working conditions (amazon ec2 free tier, Windows Server 2022)

@phrostb
Copy link

phrostb commented Dec 26, 2023

Just got the same error on Windows 11.. yesterday it was working fine. Today, I get the following

11:33:56: Cannot connect to Twitch, retrying in 30 seconds...
11:34:31: Cannot connect to Twitch, retrying in 60 seconds...
11:34:38: Earned points for watching: 10, total: 261263
11:34:38: Claimed bonus points: 50
11:34:39: Earned points for watching: 50, total: 261313
11:35:36: Cannot connect to Twitch, retrying in 141 seconds...
11:38:01: Cannot connect to Twitch, retrying in 180 seconds...

Even tried a fresh copy of 16.dev.6e0b461

@DevilXD
Copy link
Owner

DevilXD commented Dec 26, 2023

I'm really not sure what else to say here. This is an issue related to your operating system, not the miner. Details of the SSL error and what to do with it can be found here: #386 (comment)
You can verify that's the error you're running into, by disabling request error handling via these instructions: #386 (comment)

I'll probably make it so that this particular error is allowed to "bubble out", while other ones will cause the usual retry loop. That'll make more sense in the long run.

@phrostb
Copy link

phrostb commented Dec 26, 2023

Thanks for the reply and for your continued work on the project.
It seems to be working fine now.. I've made no changes to my system in the past few days. Must have been related to some sort of outage.

@Stiphr
Copy link

Stiphr commented Jan 14, 2024

Just got the same error on Windows 11.. yesterday it was working fine. Today, I get the following

11:33:56: Cannot connect to Twitch, retrying in 30 seconds... 11:34:31: Cannot connect to Twitch, retrying in 60 seconds... 11:34:38: Earned points for watching: 10, total: 261263 11:34:38: Claimed bonus points: 50 11:34:39: Earned points for watching: 50, total: 261313 11:35:36: Cannot connect to Twitch, retrying in 141 seconds... 11:38:01: Cannot connect to Twitch, retrying in 180 seconds...

Even tried a fresh copy of 16.dev.6e0b461

i'm facing the same issue, I tried this on Windows 11 (Desktop) and Raspberry Pi 5 (Pi OS)

@someC0d3r
Copy link

FYI

By using the latest version of master it works now on my VM without doing the change mentioned in #386 (comment)

91f2dac: Use truststore on Windows in Python 3.10+

@DevilXD
Copy link
Owner

DevilXD commented Jan 15, 2024

Yes, I pushed out that commit to discourage disabling SSL as a "solution", per discussion under #415. Disabling SSL is not a safe solution by any means. I'd rather have an additional dependency that disable all web security measures.

@guihkx
Copy link
Contributor

guihkx commented Feb 2, 2024

I just started getting this error, out of nowhere. Twitch on the browser works just fine.

After applying the suggestion from #386 (comment) to figure out what the exception is, I always get this one (even after multiple app restarts and token renewals):

Click me to expand
17:46:55: Logging level: CALL
17:46:56: INFO: Checking login
17:46:56: INFO: Restoring session from cookie
17:46:57: INFO: Login successful, user ID: XXXXXX
17:46:57: INFO: Websocket[0] connecting...
17:46:58: INFO: Websocket[0] connected.
17:47:05: Fatal error encountered:
17:47:05: 
17:47:05: Traceback (most recent call last):
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/env/lib/python3.11/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
17:47:05:     return await self._loop.create_connection(*args, **kwargs)
17:47:05:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/usr/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
17:47:05:     sock = await self._connect_sock(
17:47:05:            ^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/usr/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
17:47:05:     await self.sock_connect(sock, address)
17:47:05:   File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
17:47:05:     return await fut
17:47:05:            ^^^^^^^^^
17:47:05: asyncio.exceptions.CancelledError
17:47:05: 
17:47:05: The above exception was the direct cause of the following exception:
17:47:05: 
17:47:05: Traceback (most recent call last):
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/env/lib/python3.11/site-packages/aiohttp/client.py", line 574, in _request
17:47:05:     conn = await self._connector.connect(
17:47:05:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/env/lib/python3.11/site-packages/aiohttp/connector.py", line 544, in connect
17:47:05:     proto = await self._create_connection(req, traces, timeout)
17:47:05:             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/env/lib/python3.11/site-packages/aiohttp/connector.py", line 911, in _create_connection
17:47:05:     _, proto = await self._create_direct_connection(req, traces, timeout)
17:47:05:                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/env/lib/python3.11/site-packages/aiohttp/connector.py", line 1204, in _create_direct_connection
17:47:05:     transp, proto = await self._wrap_create_connection(
17:47:05:                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/env/lib/python3.11/site-packages/aiohttp/connector.py", line 989, in _wrap_create_connection
17:47:05:     async with ceil_timeout(
17:47:05:   File "/usr/lib/python3.11/asyncio/timeouts.py", line 111, in __aexit__
17:47:05:     raise TimeoutError from exc_val
17:47:05: TimeoutError
17:47:05: 
17:47:05: The above exception was the direct cause of the following exception:
17:47:05: 
17:47:05: Traceback (most recent call last):
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/main.py", line 158, in main
17:47:05:     await client.run()
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/twitch.py", line 765, in run
17:47:05:     await self._run()
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/twitch.py", line 810, in _run
17:47:05:     await self.fetch_inventory()
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/twitch.py", line 1669, in fetch_inventory
17:47:05:     await self.gui.inv.add_campaign(campaign)
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/gui.py", line 1347, in add_campaign
17:47:05:     campaign_image = await self._cache.get(campaign.image_url, size=(108, 144))
17:47:05:                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/cache.py", line 106, in get
17:47:05:     async with self._twitch.request("GET", url) as response:
17:47:05:   File "/usr/lib/python3.11/contextlib.py", line 204, in __aenter__
17:47:05:     return await anext(self.gen)
17:47:05:            ^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/twitch.py", line 1495, in request
17:47:05:     response = await self.gui.coro_unless_closed(
17:47:05:                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/gui.py", line 2050, in coro_unless_closed
17:47:05:     return await next(iter(done))
17:47:05:            ^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/env/lib/python3.11/site-packages/aiohttp/client.py", line 1174, in throw
17:47:05:     return self._coro.throw(*args, **kwargs)
17:47:05:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17:47:05:   File "/home/gui/dev/TwitchDropsMiner/env/lib/python3.11/site-packages/aiohttp/client.py", line 578, in _request
17:47:05:     raise ServerTimeoutError(
17:47:05: aiohttp.client_exceptions.ServerTimeoutError: Connection timeout to host https://static-cdn.jtvnw.net/ttv-boxart/515025.jpg
17:47:05: 
17:47:05: Exiting...
17:47:05: INFO: Websocket[0] stopped.
17:47:05: 
17:47:05: Application Terminated.
17:47:05: Close the window to exit the application.

But here's the thing, that URL opens instantly on my web browser (and even with curl):

Click me to expand
$ time curl -I https://static-cdn.jtvnw.net/ttv-boxart/515025.jpg
HTTP/2 200 
content-type: image/png
content-length: 568456
server: nginx
last-modified: Tue, 05 Dec 2023 17:24:07 GMT
x-amz-server-side-encryption: AES256
x-amz-version-id: 7IapvVNbt2WJVDtvqEggrwa8UXyblDFx
access-control-allow-origin: *
access-control-allow-methods: GET, OPTIONS
timing-allow-origin: https://www.twitch.tv
accept-ranges: bytes
date: Fri, 02 Feb 2024 20:49:42 GMT
expires: Sat, 03 Feb 2024 00:49:42 GMT
cache-control: max-age=14400
etag: "10e1c0495de9b0586a6d1139bed6c863"
vary: Accept-Encoding
x-cache: Hit from cloudfront
via: 1.1 65ffb2ded43b3ae52e7d29216ce6b644.cloudfront.net (CloudFront)
x-amz-cf-pop: GRU3-P2
x-amz-cf-id: 9a_6JVIISxLZfZE5Sv9LjuvEDKAHLHmfmbXx5PpX9ccXASzEVhyKIw==
age: 31


________________________________________________________
Executed in  270.12 millis    fish           external
   usr time   19.72 millis  301.00 micros   19.42 millis
   sys time    0.03 millis   29.00 micros    0.00 millis

DNS resolution of static-cdn.jtvnw.net is working fine on the rest of the system, too:

Click me to expand
$ time nslookup static-cdn.jtvnw.net
Server:         127.0.0.1
Address:        127.0.0.1#53

Non-authoritative answer:
static-cdn.jtvnw.net    canonical name = jtvnw.twitchcdn.net.
jtvnw.twitchcdn.net     canonical name = d186rixkn5ruba.cloudfront.net.
Name:   d186rixkn5ruba.cloudfront.net
Address: 108.139.184.218
Name:   d186rixkn5ruba.cloudfront.net
Address: 2600:9000:2619:e800:19:f28c:cd92:c761
Name:   d186rixkn5ruba.cloudfront.net
Address: 2600:9000:2619:2a00:19:f28c:cd92:c761
Name:   d186rixkn5ruba.cloudfront.net
Address: 2600:9000:2619:4800:19:f28c:cd92:c761
Name:   d186rixkn5ruba.cloudfront.net
Address: 2600:9000:2619:ae00:19:f28c:cd92:c761
Name:   d186rixkn5ruba.cloudfront.net
Address: 2600:9000:2619:7000:19:f28c:cd92:c761
Name:   d186rixkn5ruba.cloudfront.net
Address: 2600:9000:2619:d200:19:f28c:cd92:c761
Name:   d186rixkn5ruba.cloudfront.net
Address: 2600:9000:2619:6000:19:f28c:cd92:c761
Name:   d186rixkn5ruba.cloudfront.net
Address: 2600:9000:2619:e200:19:f28c:cd92:c761


________________________________________________________
Executed in   28.27 millis    fish           external
   usr time   10.09 millis  438.00 micros    9.65 millis
   sys time    6.45 millis   31.00 micros    6.42 millis

I'm out of ideas to debug this further.


EDIT: Great, I started the app in debug mode (-vvvv), and everything began working. I restarted in normal mode, and everything worked as well. Whatever this was, it was most likely temporary... -_-

@DevilXD
Copy link
Owner

DevilXD commented Feb 2, 2024

aiohttp.client_exceptions.ServerTimeoutError: Connection timeout to host https://static-cdn.jtvnw.net/ttv-boxart/515025.jpg

That looks like just a server timeout. An actual one. The miner was working as intended 🙂 It should succeed once the server responds again.

everything began working. I restarted in normal mode, and everything worked as well.

Heh 😄 Yeah, requests and connection stability is something each application just needs to take care of. There's many things that can go wrong, the server goes down, the internet connection is down or simply struggling at the time, poor wi-fi signal, the list is quite long. I wonder if there should be some more variety to the error messages, as it's only really just this one, and one that says "Twitch is down", but that only displays on 5XX responses from the server.

@WrayOfSunshine
Copy link

I reliably get the "cannot connect" message after a while, now, too. Beginning to wonder if there's some intentional behavior on the server's part to pooch TDM. I'll see if I'm getting any interesting error messages when I have time to troubleshoot.

@DevilXD DevilXD added the Solved This issue has been resolved label Jun 22, 2024
@DevilXD
Copy link
Owner

DevilXD commented Jun 22, 2024

Since there was no reports on this for a while now, I'm assuming this issue has resolved itself, and can now be closed.

@DevilXD DevilXD closed this as completed Jun 22, 2024
@hakutzu
Copy link

hakutzu commented Oct 19, 2024

image

Any fix ?

@WrayOfSunshine
Copy link

I still get this issue, but I've just been fixing it by closing and reopening the client.

@hakutzu
Copy link

hakutzu commented Oct 19, 2024

I still get this issue, but I've just been fixing it by closing and reopening the client.

Tried that multiple times, been tryin to fix this for few hours, not sure whats been going wrong.

@JourneyOver
Copy link

JourneyOver commented Oct 19, 2024

@hakutzu you are running a forked version (specifically Windows200000 fork) going by your screenshot, I'd suggest you bring the issue up over there to them instead otherwise grab the dev build from the release section of this repo (or build from this repo source instead of a forks source) and try it instead and see if you get the same problem.

@DevilXD
Copy link
Owner

DevilXD commented Oct 19, 2024

Yeah, I recommend making sure one is reporting an issue in the appropriate place. I can't exactly help with running a fork, you'll need to report it under the fork's project, not here.

Also, this is a kind reminder that closed issues with no activity for a while should usually remain closed. If you're experiencing a similar issue as described in a past issue, please just create a new issue, and attach a mention/link to the past issue you think is relevant.

Repository owner locked as resolved and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Something isn't working Solved This issue has been resolved
Projects
None yet
Development

No branches or pull requests