sock request to docker
kootenpv opened this issue · 0 comments
kootenpv commented
I wonder how I can make the socket work locally to docker:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("www.httpbin.org", 80))
http=b"""GET /get HTTP/1.1
Host: www.httpbin.org
User-Agent: python-requests/2.27.1
Accept-Encoding: gzip, deflate, br
Accept: */*
Connection: keep-alive
"""
sock.sendall(http)
sock.recv(4096)
this works for the hosted HTTP version
but when I attempt it locally:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 8001))
http=b"""GET /get HTTP/1.1
Host: localhost:8001
User-Agent: python-requests/2.27.1
Accept-Encoding: gzip, deflate, br
Accept: */*
Connection: keep-alive
"""
sock.sendall(http)
sock.recv(4096)
it doesn't work (gives back b""
)
any idea how come?
docker info:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a807e21c55f7 kennethreitz/httpbin "gunicorn -b 0.0.0.0…" 51 minutes ago Up 51 minutes 0.0.0.0:8001->80/tcp, :::8001->80/tcp exciting_dewdney