Giter Site home page Giter Site logo

discord-gateway's People

Contributors

arhsm avatar bluenix2 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

discord-gateway's Issues

ValueError: Cannot parse hostname out of URI 'gateway.discord.gg'

`
import socket
import ssl
import threading
import time
from sys import platform

import certifi
from discord_gateway import DiscordConnection

import socks # pip install PySocks

TOKEN = '********************************'
RECV_SIZE = 65536
SERVER_NAME = 'gateway.discord.gg'

socks.set_default_proxy(socks.HTTP, "127.0.0.1", 7890)
socket.socket = socks.socksocket

def heartbeat(conn, sock):
while True:
sock.send(conn.heartbeat())
time.sleep(conn.heartbeat_interval)

def recv_event(conn, sock):
while True:
for event in conn.events():
return event

    for to_send in conn.receive(sock.recv(RECV_SIZE)):
        sock.send(to_send)

def main():
# Setup the socket and SSL for the WebSocket Secure connection.
conn = DiscordConnection(SERVER_NAME, encoding='json')
ctx = ssl.create_default_context(cafile=certifi.where())

sock = socket.create_connection(conn.destination)

sock = ctx.wrap_socket(sock, server_hostname=SERVER_NAME)

sock.send(conn.connect())  # Convert to a WebSocket

# Receive the very first HELLO event.
hello = recv_event(conn, sock)

# Send RESUME or IDENTIFY depending on state (will always be False
# when initially connecting, but may be different when reconnecting).
if conn.should_resume:
    sock.send(conn.resume(TOKEN))
else:
    sock.send(conn.identify(
        token=TOKEN,
        intents=65535,
        properties={
            '$os': platform,
            '$browser': 'discord-gateway',
            '$device': 'discord-gateway'
        },
    ))

heartbeater = threading.Thread(target=heartbeat, args=(conn, sock))
heartbeater.start()

try:
    while True:
        event = recv_event(conn, sock)
        print('Received:', event)
finally:
    sock.shutdown(socket.SHUT_WR)
    sock.close()

if name == 'main':
main()`

`

Traceback (most recent call last):
File "F:\code\dc-monitor\dc_websocket.py", line 78, in
main()
File "F:\code\dc-monitor\dc_websocket.py", line 41, in main
sock = socket.create_connection(conn.destination)
^^^^^^^^^^^^^^^^
File "F:\code\dc-monitor\venv\Lib\site-packages\discord_gateway\conn.py", line 171, in destination
raise ValueError(f"Cannot parse hostname out of URI '{self.uri}'")
ValueError: Cannot parse hostname out of URI 'gateway.discord.gg'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.