본문 바로가기
파이썬

파이썬 Python, HTTPS GET with basic authentication

by º기록 2020. 9. 28.
반응형

파이썬을 사용하여 기본 인증으로 HTTPS GET을 시도하고 있습니다. 나는 파이썬을 처음 접했고 가이드는 다른 라이브러리를 사용하여 일을하는 것 같습니다. (http.client, httplib 및 urllib). 누구든지 그 방법을 보여줄 수 있습니까? 표준 라이브러리에 사용을 어떻게 알릴 수 있습니까?

 

해결 방법

 


from http.client 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()  

 

참조 페이지 https://stackoverflow.com/questions/6999565

 

 

반응형

댓글