Skip to content

Instantly share code, notes, and snippets.

@roman-tiukh
Forked from ndavison/socket-https-client.py
Created January 30, 2020 08:25
Show Gist options
  • Select an option

  • Save roman-tiukh/e3bc4b16898f8c91321825eae05acb19 to your computer and use it in GitHub Desktop.

Select an option

Save roman-tiukh/e3bc4b16898f8c91321825eae05acb19 to your computer and use it in GitHub Desktop.
Python socket HTTPS client connection example
# !/bin/env python
"""
A simple example of using Python sockets for a client HTTPS connection.
Forked for Python3
"""
import ssl
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('github.com', 443))
sock = ssl.wrap_socket(
sock,
# keyfile=None,
# certfile=None,
server_side=False,
cert_reqs=ssl.CERT_NONE,
ssl_version=ssl.PROTOCOL_SSLv23
)
sock.send(b"GET / HTTP/1.1\r\nHost: github.com\r\nConnection: close\r\n\r\n")
while True:
new = sock.recv(4096)
if not new:
sock.close()
break
print(new.decode(), end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment