• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Python, SQL 게시판 requests.get() ssl 에러

requests.get() ssl 에러

5 글 보임 - 1 에서 5 까지 (총 5 중에서)
  • 글쓴이
  • #38318

    김동하
    참가자
    from selenium import webdriver;
    from selenium.webdriver.common.keys import Keys;
    import requests
    driver = webdriver.Chrome('/Users/dongha0917/python/chromedriver');
    driver.implicitly_wait(10)
    driver.get('https://www.google.com/imghp')
    q = driver.find_element_by_css_selector('input[name="q"]')
    q.send_keys("사과");
    q.send_keys(Keys.ENTER);
    sel = driver.find_elements_by_class_name('wXeWr')[0]
    sel.click();
    img = driver.find_element_by_css_selector('img.KAlRDb');
    img_url = img.get_attribute('src');
    file_name = "1." + img_url.split('.')[-1];
    img_data = requests.get(img_url)
    f = open(file_name, 'wb');
    f.write(img_data.content)
    코드는 구글 이미지검색에서 사과 검색하고 첫번쨰 사진눌러서 큰사진의링크를 얻고 저장하는 코드가목적입니다. 하지만 urlretrieve를 사용해도 되지않습니다
    검색했는데도 해결방법을 정말많이 시도하였스나 해결이되지않아 질문드립니다
    
    
    /usr/local/bin/python3 /Users/dongha0917/python/app.py
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1348, in do_open
        h.request(req.get_method(), req.selector, req.data, headers,
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1282, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1328, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1277, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1037, in _send_output
        self.send(msg)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 975, in send
        self.connect()
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1454, in connect
        self.sock = self._context.wrap_socket(self.sock,
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 513, in wrap_socket
        return self.sslsocket_class._create(
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1071, in _create
        self.do_handshake()
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1342, in do_handshake
        self._sslobj.do_handshake()
    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "/Users/dongha0917/python/app.py", line 15, in <module>
        urllib.request.urlretrieve(img_url, file_name)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 241, in urlretrieve
        with contextlib.closing(urlopen(url, data)) as fp:
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
        return opener.open(url, data, timeout)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 519, in open
        response = self._open(req, data)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 536, in _open
        result = self._call_chain(self.handle_open, protocol, protocol +
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
        result = func(*args)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1391, in https_open
        return self.do_open(http.client.HTTPSConnection, req,
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1351, in do_open
        raise URLError(err)
    urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)>
    #38336

    codingapple
    키 마스터
    파이썬 설치시 python.org에서 다운받아서 설치하셨나요 
    아니면 이런거 따라합시다 
    https://stackoverflow.com/questions/68275857/urllib-error-urlerror-urlopen-error-ssl-certificate-verify-failed-certifica
    
    #38367

    김동하
    참가자
    어 python.org에서 받는게 아닌가여?
    #38368

    김동하
    참가자
    10번정도 따라했는데 오류 해결이 되지않습니다...
    #38376

    codingapple
    키 마스터
    ssl이나 certifi 패키지 설치해봅시다 
    https://exerror.com/urllib-error-urlerror-urlopen-error-ssl-certificate_verify_failed-certificate-verify-failed-unable-to-get-local-issuer-certificate/#:~:text=error.-,URLError%3A%20urlopen%20error%20%5BSSL%3A%20CERTIFICATE_VERIFY_FAILED%5D%20certificate%20verify%20failed,Then%20Select%20Python%20folder%20(%20Python3.
5 글 보임 - 1 에서 5 까지 (총 5 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠