#🔒 socket
66 messages · Page 1 of 1 (latest)
@sand ocean
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
hey can u copy the code and send it here as text
I think it's the extra () around HOST and PORT
!d socket.socket.connect
socket.connect(address)```
Connect to a remote socket at *address*. (The format of *address* depends on the address family — see above.)
If the connection is interrupted by a signal, the method waits until the connection completes, or raises a [`TimeoutError`](https://docs.python.org/3/library/exceptions.html#TimeoutError) on timeout, if the signal handler doesn’t raise an exception and the socket is blocking or has a timeout. For non-blocking sockets, the method raises an [`InterruptedError`](https://docs.python.org/3/library/exceptions.html#InterruptedError) exception if the connection is interrupted by a signal (or the exception raised by the signal handler).
Raises an [auditing event](https://docs.python.org/3/library/sys.html#auditing) `socket.connect` with arguments `self`, `address`.
no, that's right
its a timeout
where'd that ip come from?
oh right
import socket
HOST = "4.228.31.150"
PORT = 80
C = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
C.connect((HOST, PORT))
if C.connect:
print("Connected")
Request HTTP basic
C.send(b"GET / HTTP/1.1\r\nHost: github.com\r\n\r\n")
resposta = C.recv(4096)
if resposta:
print(resposta.decode(errors="ignore"))
else:
print("not response")
C.close()
Hey @sand ocean!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
for port?
Ports below 1024 are typically reserved
import socket
host = socket.getaddrinfo("github.com", 80)[0]
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect(host[4])
socket.send(b"GET / HTTP/1.1\r\nHost: github.com\r\n\r\n")
response = socket.recv(4096)
print(response.decode(errors="ignore"))``` this works for me @sand ocean
also if C.connect is always True because socket.socket is a function, not a boolean value
Did you run it as root?
TimeoutError: [WinError 10060] A connection attempt failed because the connected component did not respond
correctly after a period of time or the established connection failed
because the connected host did not respond
no
Ok ty
@sand ocean does this snippet work?
It might be the IP
What does this "[0]" mean?
a dns query can return multiple values, [0] just takes the first
example:
$ nslookup google.com
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: google.com
Address: 142.251.34.238
Name: google.com
Address: 2607:f8b0:4009:800::200e```
same error @finite path
hm
What happened when you left?
$ uv run test.py
HTTP/1.1 301 Moved Permanently
Content-Length: 0
Location: https://github.com/``` i got this
It takes me a while to answer because I'm translating, I don't speak English
can you try a different url instead of github.com? try google or something
ok
google ✅
why is github not responding?
firewall?
Is it with every link?
You dont have any proxies or such configured do you?
Also check your firewall isn't blocking it
no
I really think the GitHub firewall is ignoring it.
Ok i think github requires a tls handshake
Otherwise it just rejects the request
Why dont u just use the requests library?
I'm learning how to use Python sockets! One thing at a time.
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.