edge-tts icon indicating copy to clipboard operation
edge-tts copied to clipboard

IPv6 not falling back to IPv4 (aiohttp upstream issue - No Happy Eyeballs support)

Open Diend2023 opened this issue 1 year ago • 21 comments

When I tried to run 'edge tts -- text' Hello, world '-- write media hello. mp3', this error occurred. I believe this is my own reason, but I cannot solve it.

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 980, in _wrap_create_connection return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1070, in create_connection raise exceptions[0] File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1054, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 963, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 501, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 541, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') OSError: [Errno 113] Connect call failed ('2620:1ec:c11::237', 443, 0, 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/bin/edge-tts", line 8, in sys.exit(main()) File "/usr/local/lib/python3.10/site-packages/edge_tts/util.py", line 136, in main loop.run_until_complete(_async_main()) File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/usr/local/lib/python3.10/site-packages/edge_tts/util.py", line 129, in _async_main await _run_tts(args) File "/usr/local/lib/python3.10/site-packages/edge_tts/util.py", line 65, in _run_tts async for chunk in tts.stream(): File "/usr/local/lib/python3.10/site-packages/edge_tts/communicate.py", line 305, in stream async with aiohttp.ClientSession( File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1141, in aenter self._resp = await self._coro File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 779, in _ws_connect resp = await self.request( File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 536, in _request conn = await self._connector.connect( File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 540, in connect proto = await self._create_connection(req, traces, timeout) File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 901, in _create_connection _, proto = await self._create_direct_connection(req, traces, timeout) File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection raise last_exc File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection transp, proto = await self._wrap_create_connection( File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 988, in _wrap_create_connection raise client_error(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host speech.platform.bing.com:443 ssl:default [Connect call failed ('2620:1ec:c11::237', 443, 0, 0)]

Diend2023 avatar May 09 '23 14:05 Diend2023

Are you connecting to a VPN with an "IPv6 killswitch"?

rany2 avatar May 09 '23 14:05 rany2

I once failed to configure VPN, but then I turned off all agents in the environment variable. I am not sure if I have completely cancelled my configuration

Diend2023 avatar May 09 '23 14:05 Diend2023

This seems like an IPv6 configuration issue on your end.

rany2 avatar May 09 '23 14:05 rany2

Indeed, it seems aiohttp does not support Happy Eyeballs: https://github.com/aio-libs/aiohttp/issues/4451

rany2 avatar May 09 '23 14:05 rany2

So should I try to turn off ipv6?

Diend2023 avatar May 09 '23 14:05 Diend2023

Could you try that and let me know?

rany2 avatar May 09 '23 14:05 rany2

yes,thank you for your help

Diend2023 avatar May 09 '23 14:05 Diend2023

Perfect, I will see if I could work around it. In the worst case I'll consider switching to another library.

rany2 avatar May 09 '23 14:05 rany2

This seems to be valid, but I have encountered a certificate issue again:

aiohttp.client_ exceptions.ClientConnectorCertificateError: Cannot connect to host speech.platform.bing.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')]

Diend2023 avatar May 09 '23 15:05 Diend2023

@wanqifa Someone is hijacking your SSL connection, are you using this at a workplace? Edit, can you run this:

curl -4vvvv https://speech.platform.bing.com
curl -6vvvv https://speech.platform.bing.com

rany2 avatar May 09 '23 15:05 rany2

The first one can run

Diend2023 avatar May 09 '23 15:05 Diend2023

@wanqifa I mean can you share the output?

rany2 avatar May 09 '23 15:05 rany2

[root@localhost ~]# curl -4vvvv https://speech.platform.bing.com

  • About to connect() to speech.platform.bing.com port 443 (#0)
  • Trying 13.107.21.237...
  • Connected to speech.platform.bing.com (13.107.21.237) port 443 (#0)
  • Initializing NSS with certpath: sql:/etc/pki/nssdb
  • CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none
  • SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  • Server certificate:
  •   subject: CN=www.bing.com
    
  •   start date: Feb 16 03:47:45 2023 GMT
    
  •   expire date: Aug 16 03:47:45 2023 GMT
    
  •   common name: www.bing.com
    
  •   issuer: CN=Microsoft RSA TLS CA 02,O=Microsoft Corporation,C=US
    

GET / HTTP/1.1 User-Agent: curl/7.29.0 Host: speech.platform.bing.com Accept: /

< HTTP/1.1 400 Bad Request < Transfer-Encoding: chunked < X-MSEdge-Ref: 0O2JaZAAAAADeWVAa6FhpQ4kUKczxXQDrU0cxRURHRTAzMjEARWRnZQ== < Date: Tue, 09 May 2023 15:09:47 GMT <

  • Connection #0 to host speech.platform.bing.com left intact

Our services aren't available right now

We're working to restore all services as soon as possible. Please check back soon.

0O2JaZAAAAADeWVAa6FhpQ4kUKczxXQDrU0cxRURHRTAzMjEARWRnZQ==

[root@localhost ~]# curl -6vvvv https://speech.platform.bing.com

  • About to connect() to speech.platform.bing.com port 443 (#0)
  • Trying 2620:1ec:c11::237...
  • Failed to connect to 2620:1ec:c11::237: Network is unreachable
  • couldn't connect to host at speech.platform.bing.com:443
  • Closing connection 0 curl: (7) Failed to connect to 2620:1ec:c11::237: Network is unreachable

Diend2023 avatar May 09 '23 15:05 Diend2023

@wanqifa Thank you, my understanding is that the SSL error only happens sometimes; right?

rany2 avatar May 09 '23 15:05 rany2

Since I started using edge-tts, this function has not been successful. But I can use it on another device

Diend2023 avatar May 09 '23 15:05 Diend2023

I use vim /opt/python3/lib/python3.9/site-packages/edge_tts/communicate.py

26 from aiohttp import TCPConnector

305 async with aiohttp.ClientSession( 306 trust_env=True,connector=TCPConnector(ssl=False) 307 )

xiaoqiuyinhetaotao avatar Jun 08 '23 09:06 xiaoqiuyinhetaotao

I use vim /opt/python3/lib/python3.9/site-packages/edge_tts/communicate.py

26 from aiohttp import TCPConnector

305 async with aiohttp.ClientSession( 306 trust_env=True,connector=TCPConnector(ssl=False) 307 )

I have tried this before, but it failed. I will try your method again

Diend2023 avatar Jun 08 '23 10:06 Diend2023

I use vim /opt/python3/lib/python3.9/site-packages/edge_tts/communicate.py

26 from aiohttp import TCPConnector

305 async with aiohttp.ClientSession( 306 trust_env=True,connector=TCPConnector(ssl=False) 307 )

This is useful, thank you very much !!!!!!!!!!!!

Diend2023 avatar Jun 08 '23 10:06 Diend2023

I use vim /opt/python3/lib/python3.9/site-packages/edge_tts/communicate.py

26 from aiohttp import TCPConnector

305 async with aiohttp.ClientSession( 306 trust_env=True,connector=TCPConnector(ssl=False) 307 )

I'm going to implement this but why did you disable SSL verification?

rany2 avatar Jun 08 '23 10:06 rany2

I use vim /opt/python3/lib/python3.9/site-packages/edge_tts/communicate.py

26 from aiohttp import TCPConnector 305 async with aiohttp.ClientSession( 306 trust_env=True,connector=TCPConnector(ssl=False) 307 )

I'm going to implement this but why did you disable SSL verification?

Perhaps the SSL certificate validation error was caused by invalid certificates in certain systems or Python versions. I have found similar issues in the issues section of aiohttp before.

Diend2023 avatar Jun 08 '23 11:06 Diend2023

I use vim /opt/python3/lib/python3.9/site-packages/edge_tts/communicate.py

26 from aiohttp import TCPConnector 305 async with aiohttp.ClientSession( 306 trust_env=True,connector=TCPConnector(ssl=False) 307 )

I'm going to implement this but why did you disable SSL verification?

Perhaps the SSL certificate validation error was caused by invalid certificates in certain systems or Python versions. I have found similar issues in the issues section of aiohttp before.

Should be resolved by https://github.com/rany2/edge-tts/commit/8f8a3342038a283917c39af11435adb729f4ce42

rany2 avatar Aug 12 '23 14:08 rany2