• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

requests.get()에서 SSL 인증서 오류

21.01.06 13:13 작성 조회수 9.2k

1

안녕하세요.

아래와 같은 오류가 나서 구글링으로 다음과 같이 수정하여 진행을 하였습니다.

r = requests.get(url, verify=False) # verify 옵션 추가

진행은 되는데 `try`구문으로 감싸지 않으면 아래와 같은 warning이 나옵니다.

lib\site-packages\urllib3\connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

혹시 컴퓨터 환경문제를 확인해 봐야 할지, 아니면 위 warning까지 없앨 수 있는 다른 방법이 있을까요?

(혹시 회사망에서 실행한게 영향이 있을지요)

# 오류 출력

Traceback (most recent call last):
  ...
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)
...
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='ac.dict.naver.com', port=443): Max retries exceeded with url: /enendict/ac?q=test&q_enc=utf-8&st=11001 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\Z\Python_--\10.크롤링\5_english_quiz.py", line 35, in <module>
    print(test("test", URL1=True))
  File "d:\Z\Python_--\10.크롤링\5_english_quiz.py", line 23, in test
    r = requests.get(url)
 ...
requests.exceptions.SSLError: HTTPSConnectionPool(host='ac.dict.naver.com', port=443): Max retries exceeded with url: /enendict/ac?q=test&q_enc=utf-8&st=11001 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

답변 1

답변을 작성해보세요.

0

워닝은 그냥 경고의 표시이므로 신경 안쓰셔도 됩니다만 꼭 워닝을 없애고 싶으시다면 아래의 코드를 작성하시면 됩니다.

requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)