Skip to content

Instantly share code, notes, and snippets.

@ndavison
Created November 19, 2014 10:03
Show Gist options
  • Select an option

  • Save ndavison/6a5d97cb8a9091cffa7a to your computer and use it in GitHub Desktop.

Select an option

Save ndavison/6a5d97cb8a9091cffa7a to your computer and use it in GitHub Desktop.

Revisions

  1. ndavison created this gist Nov 19, 2014.
    21 changes: 21 additions & 0 deletions socket-https-client.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/bin/env python
    """
    A simple example of using Python sockets for a client HTTPS connection.
    """

    import ssl
    import socket

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('github.com', 443))
    s = ssl.wrap_socket(s, keyfile=None, certfile=None, server_side=False, cert_reqs=ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_SSLv23)
    s.sendall("GET / HTTP/1.1\r\nHost: github.com\r\nConnection: close\r\n\r\n")

    while True:

    new = s.recv(4096)
    if not new:
    s.close()
    break
    print new