반응형
urllib.request.urlopen ()을 사용하여 웹 사이트 (회사 프록시 뒤에 있음)를 열려고하는데 오류가 발생합니다.
urllib.error.HTTPError: HTTP Error 407: Proxy Authentication Required
urllib.request.getproxies ()에서 프록시를 찾을 수 있지만 사용할 사용자 이름과 암호를 어떻게 지정합니까? 공식 문서에서 해결책을 찾을 수 없습니다.
해결 방법
import urllib.request as req
proxy = req.ProxyHandler({'http': r'http://username:password@url:port'})
auth = req.HTTPBasicAuthHandler()
opener = req.build_opener(proxy, auth, req.HTTPHandler)
req.install_opener(opener)
conn = req.urlopen('http://google.com')
return_str = conn.read()
참조 페이지 https://stackoverflow.com/questions/11763028
반응형
'파이썬' 카테고리의 다른 글
파이썬 How to create an array of bits in Python? (0) | 2021.02.12 |
---|---|
파이썬 Path to a file without basename (0) | 2021.02.12 |
파이썬 How do you get a query string on Flask? (0) | 2021.02.12 |
파이썬 numpy 배열의 파이썬 메모리 사용량 (0) | 2021.02.12 |
파이썬 목록 색인이 있으면 X를 수행하십시오. (0) | 2021.02.12 |
댓글