반응형
파이썬을 사용하여 기본 인증으로 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
반응형
'파이썬' 카테고리의 다른 글
파이썬 Computing cross-correlation function? (0) | 2020.09.28 |
---|---|
파이썬 How to delete a file or folder? (0) | 2020.09.28 |
파이썬 How to set a single, main title above all the subplots with Pyplot? (0) | 2020.09.28 |
파이썬 Python의 행과 열에서 최소 / 최대 값을 찾는 방법은 무엇입니까? (0) | 2020.09.27 |
파이썬 위도와 경도가있는 지리 점이 shapefile 내에 있는지 확인 (0) | 2020.09.27 |
댓글