python-websockets/websockets

No route to host----when access IPv6 address failed,no attempt was made to access an IPv4 address

m666m opened this issue · 1 comments

When I connect to wss://ws.coincap.io/ , websocket throw Exception: No route to host.

ws = websocket.WebSocket()
ws.connect('wss://ws.coincap.io/')

And I have checked the address and found that the ipv4 address can be reached:

$ ping -4 ws.coincap.io
PING  (104.18.229.2) 56(84) bytes of data.
64 bytes from 104.18.229.2 (104.18.229.2): icmp_seq=1 ttl=51 time=257 ms
64 bytes from 104.18.229.2 (104.18.229.2): icmp_seq=2 ttl=51 time=301 ms
64 bytes from 104.18.229.2 (104.18.229.2): icmp_seq=3 ttl=51 time=256 ms
64 bytes from 104.18.229.2 (104.18.229.2): icmp_seq=4 ttl=51 time=305 ms
64 bytes from 104.18.229.2 (104.18.229.2): icmp_seq=5 ttl=51 time=276 ms
64 bytes from 104.18.229.2 (104.18.229.2): icmp_seq=6 ttl=51 time=240 ms
64 bytes from 104.18.229.2 (104.18.229.2): icmp_seq=7 ttl=51 time=301 ms
^C

$ ping -6 ws.coincap.io
PING ws.coincap.io(2606:4700::6812:e502) 56 data bytes
From sweethome (2408:8214:11a:fb61:25c4:5074:3320:35da) icmp_seq=1 Destination unreachable: Address unreachable
From sweethome (2408:8214:11a:fb61:25c4:5074:3320:35da) icmp_seq=2 Destination unreachable: Address unreachable
From sweethome (2408:8214:11a:fb61:25c4:5074:3320:35da) icmp_seq=3 Destination unreachable: Address unreachable
ping: sendmsg: No route to host
From sweethome (2408:8214:11a:fb61:25c4:5074:3320:35da) icmp_seq=4 Destination unreachable: Address unreachable
From sweethome (2408:8214:11a:fb61:25c4:5074:3320:35da) icmp_seq=5 Destination unreachable: Address unreachable
From sweethome (2408:8214:11a:fb61:25c4:5074:3320:35da) icmp_seq=7 Destination unreachable: Address unreachable
From sweethome (2408:8214:11a:fb61:25c4:5074:3320:35da) icmp_seq=8 Destination unreachable: Address unreachable
From sweethome (2408:8214:11a:fb61:25c4:5074:3320:35da) icmp_seq=9 Destination unreachable: Address unreachable
^C

curl will attempt use ipv4 address when ipv6 address fails:

$ curl -vvv ws.coincap.io
*   Trying [2606:4700::6812:e502]:80...
*   Trying 104.18.230.2:80...
* Connected to ws.coincap.io (104.18.230.2) port 80 (#0)
> GET / HTTP/1.1
> Host: ws.coincap.io
> User-Agent: curl/8.0.1
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Date: Mon, 26 Feb 2024 04:34:37 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 17
< Connection: keep-alive
< Location: https://ws.coincap.io/
< CF-Cache-Status: DYNAMIC
< Server: cloudflare
< CF-RAY: 85b57a0a398517d2-SJC
< 
* Connection #0 to host ws.coincap.io left intact
Moved Permanently

How can I set websocket to use the reachable ip address ?

ws = websocket.WebSocket() isn't the API of this library. You filed this issue against the wrong repo.