Python, HTTPS GET with basic authentication -
im trying https basic authentication using python. im new python , guides seem use diffrent librarys things. (http.client, httplib , urllib). can show me how done? how can tell standard library use?
in python 3 following work. using lower level http.client standard library. check out section 2 of rfc2617 details of basic authorization. code won't check certificate valid, set https connection. see http.client docs on how that.
from http.client import httpsconnection base64 import b64encode #this sets https connection c = httpsconnection("www.google.com") #we need base 64 encode #and decode acsii python 3 stores byte string userandpass = b64encode(b"username:password").decode("ascii") headers = { 'authorization' : 'basic %s' % userandpass } #then connect c.request('get', '/', headers=headers) #get response res = c.getresponse() # @ point check status etc # gets page text data = res.read()
Comments
Post a Comment