python

Python request proxy 서버 호출(Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP)

babbeolicoding 2023. 10. 16. 22:04

python에서 request로 URL을 호출하는 경우

아래 에러가 발생하는 경우가 있다.

 

HTTPSConnectionPool(host='abc.host.com', port=443): Max retries exceeded with url: /connect/token (Caused by ProxyError('Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy', SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:877)'),)))

 

얼핏 보면 SSL 에러라고 생각할 수 있다.

구글링 해보니 보통 verify를 false로 변환하면 문제를 해결할 수 있다고 한다.

하지만 proxy를 사용 중인 서버를 호출할 땐 verify를 변환하는 것만으로

문제를 해결하지 못한다.

 

 

이런 경우 request로 proxy를 사용하고 있는 서버를 호출할 때는 proxies가 필요하다.

proxies = {'http':'http://serverip1:port1','https':'http://serverip2:port2'}
response = requests.post(API_HOST, headers=headers, data=m, proxies=proxies, verify=True)

 

proxies 안에는 http, https 값에 proxy서버 정보를 넣어주면 된다.

http와 https는 서버마다 다르겠지만 proxy 서버를 접속해서 env 명령어를 통해서 확인이 가능하다.

$ env | grep "PROXY"
HTTP_PROXY=http://127.0.0.1:8888
HTTPS_PROXY=https://127.0.0.1:8888

 

해당 내용을 자세히 알고 싶다면 에러 메시지로 나온 아래 주소를 방문하면 확인이 가능하다.

https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy

 

Advanced Usage - urllib3 1.26.17 documentation

Previous User Guide

urllib3.readthedocs.io

 

'python' 카테고리의 다른 글

Python No module named 'Bot' 에러 해결  (0) 2023.10.30