Error 내용
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "C:\Python310\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
raise err
File "C:\Python310\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 연결된 구성원으로부터 응답이 없어 연결하지 못했거나, 호스트로부터 응답이 없어 연결이 끊어졌습니다
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Python310\lib\site-packages\urllib3\connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python310\lib\site-packages\urllib3\connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "C:\Python310\lib\http\client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Python310\lib\http\client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Python310\lib\http\client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Python310\lib\http\client.py", line 1037, in _send_output
self.send(msg)
File "C:\Python310\lib\http\client.py", line 975, in send
self.connect()
File "C:\Python310\lib\site-packages\urllib3\connection.py", line 205, in connect
conn = self._new_conn()
File "C:\Python310\lib\site-packages\urllib3\connection.py", line 179, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0x0000026A3AB800D0>, 'Connection to apis.data.go.kr timed out. (connect timeout=None)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\Python310\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Python310\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='apis.data.go.kr', port=80): Max retries exceeded with url: /1611000/ApHusEnergyUseInfoOfferService/getHsmpApHusUsgQtyInfoSearch?serviceKey=hyouGNtSkE86oIKKHuwuG%2BYsdqHgw53ODXAedf7t5iLFSjh8mjhv7tbHgv5nWsH4P056bVE4CojNYR4BFMwOXQ%3D%3D&kaptCode=A15809702&reqDate=202001 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000026A3AB800D0>, 'Connection to apis.data.go.kr timed out. (connect timeout=None)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\TSM\OneDrive\바탕 화면\pythoncode\kaptget.py", line 32, in get_energy
response = requests.get(url, params=params)
File "C:\Python310\lib\site-packages\requests\api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "C:\Python310\lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python310\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python310\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\Python310\lib\site-packages\requests\adapters.py", line 553, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='apis.data.go.kr', port=80): Max retries exceeded with url: /1611000/ApHusEnergyUseInfoOfferService/getHsmpApHusUsgQtyInfoSearch?serviceKey=hyouGNtSkE86oIKKHuwuG%2BYsdqHgw53ODXAedf7t5iLFSjh8mjhv7tbHgv5nWsH4P056bVE4CojNYR4BFMwOXQ%3D%3D&kaptCode=A15809702&reqDate=202001 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000026A3AB800D0>, 'Connection to apis.data.go.kr timed out. (connect timeout=None)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "C:\Python310\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
raise err
File "C:\Python310\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 연결된 구성원으로부터 응답이 없어 연결하지 못했거나, 호스트로부터 응답이 없어 연결이 끊어졌습니다
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Python310\lib\site-packages\urllib3\connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python310\lib\site-packages\urllib3\connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "C:\Python310\lib\http\client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Python310\lib\http\client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Python310\lib\http\client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Python310\lib\http\client.py", line 1037, in _send_output
self.send(msg)
File "C:\Python310\lib\http\client.py", line 975, in send
self.connect()
File "C:\Python310\lib\site-packages\urllib3\connection.py", line 205, in connect
conn = self._new_conn()
File "C:\Python310\lib\site-packages\urllib3\connection.py", line 179, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0x0000026A3AB81C00>, 'Connection to apis.data.go.kr timed out. (connect timeout=None)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\Python310\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Python310\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='apis.data.go.kr', port=80): Max retries exceeded with url: /1611000/ApHusEnergyUseInfoOfferService/getHsmpApHusUsgQtyInfoSearch?serviceKey=hyouGNtSkE86oIKKHuwuG%2BYsdqHgw53ODXAedf7t5iLFSjh8mjhv7tbHgv5nWsH4P056bVE4CojNYR4BFMwOXQ%3D%3D&kaptCode=A15809702&reqDate=202001 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000026A3AB81C00>, 'Connection to apis.data.go.kr timed out. (connect timeout=None)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\TSM\OneDrive\바탕 화면\pythoncode\kaptget.py", line 90, in <module>
File "c:\Users\TSM\OneDrive\바탕 화면\pythoncode\kaptget.py", line 37, in get_energy
response = requests.get(url, params=params)
File "C:\Python310\lib\site-packages\requests\api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "C:\Python310\lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python310\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python310\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\Python310\lib\site-packages\requests\adapters.py", line 553, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='apis.data.go.kr', port=80): Max retries exceeded with url: /1611000/ApHusEnergyUseInfoOfferService/getHsmpApHusUsgQtyInfoSearch?serviceKey=hyouGNtSkE86oIKKHuwuG%2BYsdqHgw53ODXAedf7t5iLFSjh8mjhv7tbHgv5nWsH4P056bVE4CojNYR4BFMwOXQ%3D%3D&kaptCode=A15809702&reqDate=202001 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000026A3AB81C00>, 'Connection to apis.data.go.kr timed out. (connect timeout=None)'))
Error 원인
- api 요청을 반복적으로 보내면, 해당 웹사이트에서 이를 로봇으로 판단하거나, 일시적인 인터넷 연결 문제가 발생하면 TimeoutError, URLError를 띄움
Error 해결
- 웹서버에 반복적인 요청을 할 때 에러가 발생하면, 일정시간 동안 쉬었다가 다시 재시도 (time.sleep(1) 정도가 적당하다던데)