본문으로 바로가기

파일의 IT 블로그

  1. Home
  2. 프로그래밍/Python
  3. [Python] Requests 와 Fiddler 동시에 이용하기

[Python] Requests 와 Fiddler 동시에 이용하기

· 댓글개 · KRFile

피들러가 켜져 있는 상태에서 https 규약 사이트를 Requests로 Post() Get()을 하려고 하면 오류가 납니다.

SSL 인증서(보안 문제)와 연관이 있는거 같은데요.

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


1. Tools - Options 로 이동합니다.

 

2. Decrypt HTTPS traffic 가 체크가 안 돼있다면 체크하고 인증서를 설치해줍니다.

 

3. Actions - Export Root Certificate to Desktop을 통해 인증서 파일을 내보냅니다.

이후 바탕화면에 FiddlerRoot.cer 파일이 생성되었다면 성공입니다.

 

4. https://sourceforge.net/projects/openssl/

 

OpenSSL

Download OpenSSL for free. This project offers OpenSSL for Windows (static as well as shared). It supports: FIPS Object Module 1.2 and CAPI engine.

sourceforge.net

위 사이트로 이동하여 OpenSSL을 다운로드합니다.

 

5. bin 폴더 안에 FiddlerRoot.cer을 넣어줍니다.

이후 openssl.exe를 실행합니다.

 

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

6. 위 코드를 콘솔에 입력합니다. openssl.exe 와 같은 경로에 FiddlerRoot.pem 이 생겼다면 성공입니다 ^^

이 파일을 실행하려는. py 파일과 동일 경로에 두시고...

 

Requests에서 Post나 Get을 할 때

proxies={"http": "http://127.0.0.1:8888", "https":"http:127.0.0.1:8888"}, verify=r"FiddlerRoot.pem"

해당 속성을 주시면 됩니다. 아래는 예제입니다.

 

url = "Enter Ur Url"
headers = {
            'Content-Type': 'application/json; charset=utf-8',
             'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
           }
res = requests.session() #세션 유지
response = res.get(url, headers=headers, proxies={"http": "http://127.0.0.1:8888", "https":"http:127.0.0.1:8888"}, verify=r"FiddlerRoot.pem")

 

SNS 공유하기
💬 댓글 개
이모티콘창 닫기
울음
안녕
감사해요
당황
피폐

이모티콘을 클릭하면 댓글창에 입력됩니다.