인프런 커뮤니티 질문&답변

ohhoi88님의 프로필 이미지
ohhoi88

작성한 질문수

[2024 개정판] 이것이 진짜 크롤링이다 - 기본편

네이버에서 크롤링 하는데 자꾸 에러가 뜹니다.

작성

·

1K

1

py 파일에서 실행하면 계속 아래와 같이 에러가 뜨네요.

import requests

response = requests.get("https://www.naver.com")
html = response.text
print(html)

 

 

Traceback (most recent call last):
  File "d:\000. ����\000. �� ����\���α׷���\��ũ�Ѹ�_�⺻\Chap.3\req1.py", line 5, in <module>
    print(html)
UnicodeEncodeError: 'cp949' codec can't encode character '\u22ef' in position 10244: illegal multibyte sequence

그리고 어떨 때는 아래와 같이 에러가 뜹니다.

Traceback (most recent call last):
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 416, in connect
    self.sock = ssl_wrap_socket(
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create
    self.do_handshake()
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, 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 "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 440, in send
    resp = conn.urlopen(
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.naver.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[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 "d:\000. ����\000. �� ����\���α׷���\��ũ�Ѹ�_�⺻\Chap.3\req1.py", line 3, in <module>
    response = requests.get("https://www.naver.com")
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\HEC\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.naver.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))

 

 

그런데 신기한 점은 ipynb 파일에선 문제없이 실행됩니다.

대체 어떻게 해야하죠? 몇시간동안 해매고있습니다.

 

답변 1

0

스타트코딩님의 프로필 이미지
스타트코딩
지식공유자

안녕하세요.

코딩을 가장 쉽게 알려주는 크리에이터 스타트코딩입니다.

 

흠.. 뭔가 제 생각에

환경설정 (파이썬 설치 및 vscode 설치)이 잘못 된 것 같습니다.

 

https://youtu.be/REUu0T1xsiU

위 영상 6:40 부터 따라 하면서

파이썬, vscode를 전체 삭제 후 재설치 해보시기 바랍니다 ^^

 

- 스타트코딩 드림. 

 

ohhoi88님의 프로필 이미지
ohhoi88

작성한 질문수

질문하기