Good day, I’m having a little problem…i want to connect a website’s server and the URI looks like this
I asked for help on a discord server and someone sent a link to socket.py
I’m here looking at it and i have no idea on what I’m meant to change or do… please can you help to enlighten me… I’ll be so grateful
I think a better choice would be the requests module:
requests · PyPI
For receiving the binary messages from the socket?
I think the picture shows a web API, where you talk to it by passing parameters in the URL and it returns JSON data, or similar.
socket module is very low level; the
requests module is higher level and provides much more functionality, making the task of using a web API much easier.
You could use the
sockets module, but you’d probably end up replicating functionality that the
requests module already offers.
You can’t do WebSockets with Python’s socket module on its own. The socket module provides low-level interface to Kernel’s BSD-style socket stack on OSI level 3 and 4 (e.g. TCP, UDP / IPv4, IPv6). Whoever pointed you to socket module gave you a bad advise.
WebSockets use a different protocol stack on OSI level 7. WSS are typically upgraded from a HTTP connection over TLS (hence the second ‘s’ for secure’). There are a bunch of libraries for WebSockets. wsproto · PyPI seems to be a good choice.
If you’re using asyncio, the aptly-named websockets module does a great job. Can do both servers and clients, although it doesn’t do mixed HTTP and WS servers.
Does Websocket-client work too because when i tried that a while ago it didn’t work @Rosuav
No idea, I haven’t used that one.
Please can you show me a code of yours or something cause i remember trying websockets too…months back and I think it ended up being the same thing .in my terminal 40 was sent and then 41… connection then closed @Rosuav