Skip to content

Bug: Unhandled exception in rest_client_base.py #71

@gohm-tech

Description

@gohm-tech

When there is a problem with network (or no connection at all), the post function inside login function (rest_client_base.py file) is creating unhandled exceptions. I thing this post function needs timeout, and this function needs to be encapsulated in a try except condition.
tb_rest_client version is 1.3.2

The steps to reproduce:
1- Without and active internet connection, call rest_client.login(username=self.username, password=self.password)
2- you will get error like this:

Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     conn.connect()
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 353, in connect
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     conn = self._new_conn()
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 181, in _new_conn
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     raise NewConnectionError(
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]: urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0xb43c71c0>: Failed to establish a new connection: [Errno 113] No route to host
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]: During handling of the above exception, another exception occurred:
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]: Traceback (most recent call last):
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     resp = conn.urlopen(
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     retries = retries.increment(
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 574, in increment
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     raise MaxRetryError(_pool, url, error or ResponseError(cause))
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]: urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='[load.molisens.com](http://load.molisens.com/)', port=443): Max retries exceeded with url: /api/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xb43c71c0>: Failed to establish a new connection: [Errno 113] No route to host'))
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]: During handling of the above exception, another exception occurred:
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]: Traceback (most recent call last):
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/local/lib/python3.9/dist-packages/tb_rest_client/rest_client_base.py", line 56, in run
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     self.login(self.username, self.password)
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/local/lib/python3.9/dist-packages/tb_rest_client/rest_client_base.py", line 83, in login
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     token_json = post(self.base_url + "/api/auth/login", json={"username": username, "password": password},
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/requests/api.py", line 119, in post
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     return request('post', url, data=data, json=json, **kwargs)
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/requests/api.py", line 61, in request
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     return session.request(method=method, url=url, **kwargs)
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     resp = self.send(prep, **send_kwargs)
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     r = adapter.send(request, **kwargs)
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:   File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
Aug  8 14:05:33 gasgw-b827ebcd0c4f python3[3420]:     raise ConnectionError(e, request=request)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions