해결)requests.exceptions.ConnectionError: HTTPConnectionPool(host='*', port=80): Max retries exceeded with url



작성시간 :





(수정됨)

에러

에러 예시

import requests
url = 'http://dasfasdfasdf.com/'
with requests.get(url) as r:
    print(r.status_code)

>> Traceback (most recent call last):
  File "c:\seolpyo\white\0.py", line 6, in <module>
    with requests.get(url) as r:
          ^^^^^^^^^^^^^^^^^
  File "C:\seolpyo\python\Lib\site-packages\requests\api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\seolpyo\python\Lib\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\seolpyo\python\Lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\seolpyo\python\Lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\seolpyo\python\Lib\site-packages\requests\adapters.py", line 519, in send
    raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='dasfasdfasdf.com', port=80): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x000001347B76BC90>: Failed to resolve 'dasfasdfasdf.com' ([Errno 11001] getaddrinfo failed)"))

해결방법

유효한 url로 요청을 보내자.

설명

웹사이트를 기준으로 설명하자면 호스팅되지 않은 url로 요청을 보낸 것이 원인이다.
예시에 사용한 아무렇게나 입력한 url을 웹브라우저로 접속한 다음, status를 확인해보면 "(failed) net::ERR_NAME_NOT_RESOLVED"인 것을 확인할 수 있다.



태그



공유

하기






white.seolpyo.com