kindnavsync issueshttps://scm.uninett.no/verktoy/kindnavsync/-/issues2021-03-03T13:17:17+01:00https://scm.uninett.no/verktoy/kindnavsync/-/issues/3Combine kindnavsync and nettinst2room into one script2021-03-03T13:17:17+01:00Vegard VesterheimCombine kindnavsync and nettinst2room into one scriptSince it is necessary to run the two script in a specific order and almost simultaneous, we could simply combine them into one script.
This also removes any need to implement common argument parsing etc.Since it is necessary to run the two script in a specific order and almost simultaneous, we could simply combine them into one script.
This also removes any need to implement common argument parsing etc.https://scm.uninett.no/verktoy/kindnavsync/-/issues/4Intermittent exceptions when using NAV API2021-04-09T08:28:55+02:00Vegard VesterheimIntermittent exceptions when using NAV APIThe script `nettinst2room` intermittently throws Excpetions like:
can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-pac...The script `nettinst2room` intermittently throws Excpetions like:
can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/httpx/_exceptions.py", line 326, in map_exceptions
yield
File "/usr/local/lib/python3.7/dist-packages/httpx/_client.py", line 866, in _send_single_request
ext={"timeout": timeout.as_dict()},
File "/usr/local/lib/python3.7/dist-packages/httpcore/_sync/connection_pool.py", line 219, in request
method, url, headers=headers, stream=stream, ext=ext
File "/usr/local/lib/python3.7/dist-packages/httpcore/_sync/connection.py", line 106, in request
return self.connection.request(method, url, headers, stream, ext)
File "/usr/local/lib/python3.7/dist-packages/httpcore/_sync/http11.py", line 72, in request
) = self._receive_response(timeout)
File "/usr/local/lib/python3.7/dist-packages/httpcore/_sync/http11.py", line 133, in _receive_response
event = self._receive_event(timeout)
File "/usr/local/lib/python3.7/dist-packages/httpcore/_sync/http11.py", line 169, in _receive_event
event = self.h11_state.next_event()
File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.7/dist-packages/httpcore/_exceptions.py", line 12, in map_exceptions
raise to_exc(exc) from None
httpcore.RemoteProtocolError: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/simple_rest_client/decorators.py", line 29, in wrapper
response = f(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/simple_rest_client/request.py", line 25, in make_request
client_response = client_method(request.url, **client_options)
File "/usr/local/lib/python3.7/dist-packages/httpx/_client.py", line 915, in get
timeout=timeout,
File "/usr/local/lib/python3.7/dist-packages/httpx/_client.py", line 734, in request
request, auth=auth, allow_redirects=allow_redirects, timeout=timeout
File "/usr/local/lib/python3.7/dist-packages/httpx/_client.py", line 772, in send
history=[],
File "/usr/local/lib/python3.7/dist-packages/httpx/_client.py", line 809, in _send_handling_auth
history=history,
File "/usr/local/lib/python3.7/dist-packages/httpx/_client.py", line 837, in _send_handling_redirects
response = self._send_single_request(request, timeout)
File "/usr/local/lib/python3.7/dist-packages/httpx/_client.py", line 866, in _send_single_request
ext={"timeout": timeout.as_dict()},
File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.7/dist-packages/httpx/_exceptions.py", line 343, in map_exceptions
raise mapped_exc(message, **kwargs) from exc # type: ignore
httpx.RemoteProtocolError: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE
Error in fetching room for un-p000003:
Error: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE
The failed API requests do not seem to appear at all in the logs on
the server! (/var/log/apache2/nav-secure_access_ssl.log /var/log/uwsgi/app/nav.log /var/log/uwsgi/nav/nav.log)
Is this some kind of throttling on the server side?
Related to this?
https://github.com/encode/httpx/issues/1478https://scm.uninett.no/verktoy/kindnavsync/-/issues/5Handle timeouts properly2021-09-13T08:29:33+02:00Morten BrekkevoldHandle timeouts properlyThe API calls used by kindnavsync may intermittently time out. This causes massive heaps of traceback messages to be output - and if running in cron, this output is sent as annoying e-mails.
These errors should be handled more gracefull...The API calls used by kindnavsync may intermittently time out. This causes massive heaps of traceback messages to be output - and if running in cron, this output is sent as annoying e-mails.
These errors should be handled more gracefully. A combined solution would:
1. Retry a few times before giving up entirely
2. Catch timeout errors and output a much more succinct error message to the user (e.g. "The NAV API timed out")
An example:
```
2020-09-08 16:00:25,145 [ERROR] [simple_rest_client.decorators] HTTPSConnectionPool(host='uninav.uninett.no', port=443): Read timed out. (read timeout=3)
Traceback (most recent call last):
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 421, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 416, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.5/http/client.py", line 1236, in getresponse
response.begin()
File "/usr/lib/python3.5/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.5/http/client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.5/socket.py", line 576, in readinto
return self._sock.recv_into(b)
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 326, in recv_into
raise timeout("The read operation timed out")
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/mvold/.local/lib/python3.5/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 400, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/packages/six.py", line 735, in reraise
raise value
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 423, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 331, in _raise_timeout
self, url, "Read timed out. (read timeout=%s)" % timeout_value
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='uninav.uninett.no', port=443): Read timed out. (read timeout=3)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/mvold/.local/lib/python3.5/site-packages/simple_rest_client/decorators.py", line 30, in wrapper
response = f(*args, **kwargs)
File "/home/mvold/.local/lib/python3.5/site-packages/simple_rest_client/request.py", line 23, in make_request
**request.kwargs
File "/home/mvold/.local/lib/python3.5/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/home/mvold/.local/lib/python3.5/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/mvold/.local/lib/python3.5/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/mvold/.local/lib/python3.5/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='uninav.uninett.no', port=443): Read timed out. (read timeout=3)
Traceback (most recent call last):
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 421, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 416, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.5/http/client.py", line 1236, in getresponse
response.begin()
File "/usr/lib/python3.5/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.5/http/client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.5/socket.py", line 576, in readinto
return self._sock.recv_into(b)
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 326, in recv_into
raise timeout("The read operation timed out")
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/mvold/.local/lib/python3.5/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 400, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/packages/six.py", line 735, in reraise
raise value
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 423, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/home/mvold/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 331, in _raise_timeout
self, url, "Read timed out. (read timeout=%s)" % timeout_value
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='uninav.uninett.no', port=443): Read timed out. (read timeout=3)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/mvold/.local/lib/python3.5/site-packages/simple_rest_client/decorators.py", line 30, in wrapper
response = f(*args, **kwargs)
File "/home/mvold/.local/lib/python3.5/site-packages/simple_rest_client/request.py", line 23, in make_request
**request.kwargs
File "/home/mvold/.local/lib/python3.5/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/home/mvold/.local/lib/python3.5/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/mvold/.local/lib/python3.5/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/mvold/.local/lib/python3.5/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='uninav.uninett.no', port=443): Read timed out. (read timeout=3)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mvold/.local/bin/kindnavsync", line 654, in <module>
main()
File "/home/mvold/.local/bin/kindnavsync", line 77, in main
dry_run=args.dry_run,
File "/home/mvold/.local/bin/kindnavsync", line 416, in update_nav
netboxes = set(NAVBox(n) for n in nav_api.list_netboxes())
File "/home/mvold/.local/lib/python3.5/site-packages/kindnavsync/navapi.py", line 41, in list_netboxes
response = self.api.netbox.list(params={"page_size": 1000})
File "/home/mvold/.local/lib/python3.5/site-packages/simple_rest_client/resource.py", line 110, in action_method
return make_request(self.session, request)
File "/home/mvold/.local/lib/python3.5/site-packages/simple_rest_client/decorators.py", line 33, in wrapper
raise ClientConnectionError() from exc
simple_rest_client.exceptions.ClientConnectionError
```