반응형

Fiddler가 수행중인 상태에서 https 규약 사이트를 Requests로 Post() Get()을 수행하면 아래와 같은 오류가 발생합니다.

ProxyError: HTTPSConnectionPool(host='www.tistory.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1074: The handshake operation timed out')))

Fiddler 에서 인증서를 내보낼 수 있는데 이를 활용하여 해결 할 수 있습니다.

1. Tools > Options 선택

2. [HTTPS] 탭으로 이동 > Decrypt HTTPS traffic 가 체크가 안되어 있다면 체크 >  Actions - Export Root Certificate to Desktop을 클릭하여 인증서 파일 생성 (바탕화면에 FiddlerRoot.cer 파일 생성)

3. OpenSSL 다운로드 사이트로 이동하여 OpenSSL 다운로드

4. bin 폴더 안에 FiddlerRoot.cer을 붙여넣기

5. OpenSSL 실행 (openssl.exe)

6. 콘솔에서 아래 코드 입력하면 FiddlerRoot.pem 생성 (openssl.exe 와 같은 경로)

OpenSSL> x509 -inform der -in FiddlerRoot.cer -out FiddlerRoot.pem

7. FiddlerRoot.pem 파일을 파일을 실행하려는 (. py 또는 .ipynb) 파일과 동일 경로에 복사

8. (예시) Request 사용 시 proxies 추가

더보기

http://127.0.0.1 다음에 오는 port 는 Tools > Options > Connections 에서 아래 포트를 확인하시고 입력하시면 됩니다. Jupyter notebook과 Fiddler가 Default로 8888를 잡아서 다른 오류가 발생 할 수 있습니다.

session = requests.Session()
proxies = {"http": "http://127.0.0.1:8888", "https":"http:127.0.0.1:8888"}
verify = "FiddlerRoot.pem"
session.post(url='http://www.tistory.com',headers={'User-Agent': 'Chrome'}, proxies=proxies, verify=verify, timeout=3)

Fiddler를 수행하고 폐쇄망에서 작업을 하다보니 도대체 왜 안되지 확인이 어려워 한참을 고민했습니다.

반응형