Skip to content

Instantly share code, notes, and snippets.

@matrixfox
Created March 5, 2016 19:42
Show Gist options
  • Select an option

  • Save matrixfox/e7f05211e956c046a518 to your computer and use it in GitHub Desktop.

Select an option

Save matrixfox/e7f05211e956c046a518 to your computer and use it in GitHub Desktop.

Revisions

  1. matrixfox created this gist Mar 5, 2016.
    16 changes: 16 additions & 0 deletions https-con.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    from httplib import HTTPSConnection
    from base64 import b64encode
    #This sets up the https connection
    c = HTTPSConnection("www.google.com")
    #we need to base 64 encode it
    #and then decode it to acsii as python 3 stores it as a byte string
    userAndPass = b64encode(b"username:password").decode("ascii")
    headers = { 'Authorization' : 'Basic %s' % userAndPass }
    #then connect
    c.request('GET', '/', headers=headers)
    #get the response back
    res = c.getresponse()
    # at this point you could check the status etc
    # this gets the page text
    data = res.read()
    print data