My app calls wikipedia API frequently. It could work well until several weeks ago, but recently it often can't work well because of the error [Errno 101] Network is unreachable . First, I thought it's because of frequently API call, so I put sleep interval for the calls, however, that error still occurred. After that, I can restart the app soon, so it can call wikipedia API well at first, but dozens minutes later the err occurred again. A month ago, that problem haven't happened. Please help me to fix it.
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 158, in _new_conn
conn = connection.create_connection(
File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 80, in create_connection
raise err
File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 70, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
conn.connect()
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 301, in connect
conn = self._new_conn()
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 167, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f30f4bebeb0>: Failed to establish a new connection: [Errno 101] Network is unr
eachable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 637, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='ja.wikipedia.org', port=443): Max retries exceeded with url: /w/api.php?action=query&format=json&titles=%E6%85%B6%
E9%87%8E%E6%9D%BE%E5%8E%9F&prop=coordinates&coprop=type%7Cname%7Cdim%7Ccountry%7Cregion&coprimary=all (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnecti
on object at 0x7f30f4bebeb0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "csv2pop.py", line 1174, in <module>
R = S.get(url=URLjp_api, params=PARAMS)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='ja.wikipedia.org', port=443): Max retries exceeded with url: /w/api.php?action=query&format=json&titles=%E6%85%
B6%E9%87%8E%E6%9D%BE%E5%8E%9F&prop=coordinates&coprop=type%7Cname%7Cdim%7Ccountry%7Cregion&coprimary=all (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConne
ction object at 0x7f30f4bebeb0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))
07:00 ~ $