AmauryCarrade / MastodonToTwitter

Mastodon <-> Twitter cross-poster.
MIT License
250 stars 41 forks source link

Script throws and crashes if Mastodon is unavailable #43

Open ara4n opened 7 years ago

ara4n commented 7 years ago

Seems that a timed out connection to Mastodon kills the whole script with a Failed to establish a new connection: [Errno 110] Connection timed out. On restarting, any tweets/toots that happened during the downtime are lost...

``` Traceback (most recent call last): File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 141, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 83, in create_connection raise err File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 73, in create_connection sock.connect(sa) TimeoutError: [Errno 110] Connection timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 345, in _make_request self._validate_conn(conn) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 844, in _validate_conn conn.connect() File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 284, in connect conn = self._new_conn() File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 150, in _new_conn self, "Failed to establish a new connection: %s" % e) requests.packages.urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 110] Connection timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/adapters.py", line 423, in send timeout=timeout File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen _stacktrace=sys.exc_info()[2]) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/packages/urllib3/util/retry.py", line 376, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='mastodon.matrix.org', port=443): Max retries exceeded with url: /api/v1/accounts/73/statuses (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 110] Connection timed out',)) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/mastodon/Mastodon.py", line 812, in __api_request response_object = requests.get(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/api.py", line 70, in get return request('get', url, params=params, **kwargs) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/api.py", line 56, in request return session.request(method=method, url=url, **kwargs) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/sessions.py", line 488, in request resp = self.send(prep, **send_kwargs) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/sessions.py", line 609, in send r = adapter.send(request, **kwargs) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/requests/adapters.py", line 487, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='mastodon.matrix.org', port=443): Max retries exceeded with url: /api/v1/accounts/73/statuses (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 110] Connection timed out',)) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./MastodonToTwitter.py", line 243, in new_toots = mastodon_api.account_statuses(ma_account_id, since_id = since_toot_id) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/mastodon/Mastodon.py", line 363, in account_statuses return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/statuses', params) File "/home/mastodon/MastodonToTwitter/env/lib/python3.4/site-packages/mastodon/Mastodon.py", line 823, in __api_request raise MastodonNetworkError("Could not complete request: %s" % e) mastodon.Mastodon.MastodonNetworkError: Could not complete request: HTTPSConnectionPool(host='mastodon.matrix.org', port=443): Max retries exceeded with url: /api/v1/accounts/73/statuses (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 110] Connection timed out',)) ```