Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Occasional timeout with api.ipify.org #39

Closed
Snuggle opened this issue Mar 27, 2020 · 7 comments · Fixed by #43
Closed

Occasional timeout with api.ipify.org #39

Snuggle opened this issue Mar 27, 2020 · 7 comments · Fixed by #43

Comments

@Snuggle
Copy link
Contributor

Snuggle commented Mar 27, 2020

Hey! This doesn't seem to be the most major issue ever but occasionally I seem to get timeout errors from https://api.ipify.org. Perhaps it might be a good idea to use multiple redundant sources to get the machine's public IP address since a single service might one day go down. Some other external IP services include https://ifconfig.io/ or https://ident.me/ or https://ifconfig.me/ or https://icanhazip.com

Ideally if one service fails, the script would handle it and try another provider.

Mar 27 11:33:45 hug systemd[1]: Starting Automatically updates the CloudFlare DNS record upon IP address change....
Mar 27 11:33:52 hug cloudflare-ddns[9827]: Traceback (most recent call last):
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 384, in _make_request
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     six.raise_from(e, None)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "<string>", line 3, in raise_from
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 380, in _make_request
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     httplib_response = conn.getresponse()
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib64/python3.6/http/client.py", line 1346, in getresponse
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     response.begin()
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib64/python3.6/http/client.py", line 307, in begin
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     version, status, reason = self._read_status()
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib64/python3.6/http/client.py", line 268, in _read_status
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib64/python3.6/socket.py", line 586, in readinto
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     return self._sock.recv_into(b)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib64/python3.6/ssl.py", line 968, in recv_into
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     return self.read(nbytes, buffer)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib64/python3.6/ssl.py", line 830, in read
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     return self._sslobj.read(len, buffer)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib64/python3.6/ssl.py", line 587, in read
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     v = self._sslobj.read(len, buffer)
Mar 27 11:33:52 hug cloudflare-ddns[9827]: socket.timeout: The read operation timed out
Mar 27 11:33:52 hug cloudflare-ddns[9827]: During handling of the above exception, another exception occurred:
Mar 27 11:33:52 hug cloudflare-ddns[9827]: Traceback (most recent call last):
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     timeout=timeout
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     _stacktrace=sys.exc_info()[2])
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/urllib3/util/retry.py", line 368, in increment
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     raise six.reraise(type(error), error, _stacktrace)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/urllib3/packages/six.py", line 693, in reraise
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     raise value
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     chunked=chunked)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 386, in _make_request
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 306, in _raise_timeout
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
Mar 27 11:33:52 hug cloudflare-ddns[9827]: urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.ipify.org', port=443): Read timed out. (read timeout=6)
Mar 27 11:33:52 hug cloudflare-ddns[9827]: During handling of the above exception, another exception occurred:
Mar 27 11:33:52 hug cloudflare-ddns[9827]: Traceback (most recent call last):
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/local/bin/cloudflare-ddns", line 298, in <module>
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     main()
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/local/bin/cloudflare-ddns", line 279, in main
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     external_ip = get_external_ip()
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/local/bin/cloudflare-ddns", line 115, in get_external_ip
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     r = requests.get(EXTERNAL_IP_QUERY_API, timeout=6)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/requests/api.py", line 75, in get
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     return request('get', url, params=params, **kwargs)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/requests/api.py", line 60, in request
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     return session.request(method=method, url=url, **kwargs)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     resp = self.send(prep, **send_kwargs)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     r = adapter.send(request, **kwargs)
Mar 27 11:33:52 hug cloudflare-ddns[9827]:   File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 529, in send
Mar 27 11:33:52 hug cloudflare-ddns[9827]:     raise ReadTimeout(e, request=request)
Mar 27 11:33:52 hug cloudflare-ddns[9827]: requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.ipify.org', port=443): Read timed out. (read timeout=6)
Mar 27 11:33:52 hug systemd[1]: ddns.service: Main process exited, code=exited, status=1/FAILURE
Mar 27 11:33:52 hug systemd[1]: ddns.service: Failed with result 'exit-code'.
Mar 27 11:33:52 hug systemd[1]: Failed to start Automatically updates the CloudFlare DNS record upon IP address change..
Mar 27 11:35:19 hug systemd[1]: Starting Automatically updates the CloudFlare DNS record upon IP address change....
Mar 27 11:35:21 hug cloudflare-ddns[9853]: Found external IPv4: "123.123.123.123"
@zaanposni
Copy link
Contributor

Thanks for providing those other services, I will look into it.
5 services seem enough tho, after all of these failing I would generate an error asking the user to check his internet connection.

zaanposni added a commit to zaanposni/cloudflare-ddns-client that referenced this issue Apr 4, 2020
LINKIWI pushed a commit that referenced this issue Apr 4, 2020
…ed. regarding #39 (#42)

Co-authored-by: zaanposni <zaanposni@users.noreply.github.com>
@LINKIWI LINKIWI closed this as completed Apr 4, 2020
@Snuggle
Copy link
Contributor Author

Snuggle commented Apr 7, 2020

Hey, @zaanposni! This still seems like an issue, was the exception handled correctly?

Apr 07 13:20:45 hug systemd[1]: Starting Automatically updates the CloudFlare DNS record upon IP address change....
Apr 07 13:20:54 hug cloudflare-ddns[21430]: Cannot fetch your external ip. https://api.ipify.org not reachable.
Apr 07 13:20:54 hug cloudflare-ddns[21430]: Found external IPv4: "123.123.123.123
Apr 07 13:20:54 hug cloudflare-ddns[21430]: "
Apr 07 13:20:54 hug cloudflare-ddns[21430]: Listing all zones.
Apr 07 13:20:54 hug cloudflare-ddns[21430]: Finding all DNS records.
Apr 07 13:20:54 hug cloudflare-ddns[21430]: Updating the A record (ID 12345678) of (sub)domain hug.snugg.ie (ID 12345678) to 123.123.123.123
Apr 07 13:20:54 hug cloudflare-ddns[21430]: .
Apr 07 13:20:54 hug cloudflare-ddns[21430]: DNS record failed to update.
Apr 07 13:20:54 hug cloudflare-ddns[21430]: CloudFlare returned the following errors: [{'code': 1004, 'message': 'DNS Validation Error', 'error_chain': [{'code': 9041, 'message': 'This DNS record cannot be proxied - click the cloud icon to turn it gray to proceed'}]}].
Apr 07 13:20:54 hug cloudflare-ddns[21430]: CloudFlare returned the following messages: []
Apr 07 13:20:54 hug cloudflare-ddns[21430]: Listing all zones.
Apr 07 13:20:54 hug cloudflare-ddns[21430]: Finding all DNS records.
Apr 07 13:20:54 hug cloudflare-ddns[21430]: Updating the A record (ID 12345678) of (sub)domain beta.snugg.ie (ID 12345678) to 123.123.123.123
Apr 07 13:20:54 hug cloudflare-ddns[21430]: .
Apr 07 13:20:54 hug cloudflare-ddns[21430]: DNS record failed to update.
Apr 07 13:20:54 hug cloudflare-ddns[21430]: CloudFlare returned the following errors: [{'code': 1004, 'message': 'DNS Validation Error', 'error_chain': [{'code': 9041, 'message': 'This DNS record cannot be proxied - click the cloud icon to turn it gray to proceed'}]}].
Apr 07 13:20:54 hug cloudflare-ddns[21430]: CloudFlare returned the following messages: []

@Snuggle
Copy link
Contributor Author

Snuggle commented Apr 7, 2020

I am not entirely certain, but I feel like the issue may lie with this line? Only a single dot is outputted?
Apr 07 13:20:54 hug cloudflare-ddns[21430]: .

@Snuggle
Copy link
Contributor Author

Snuggle commented Apr 7, 2020

Ah, I believe newlines must be stripped!

Apr 07 13:20:54 hug cloudflare-ddns[21430]: Found external IPv4: "123.123.123.123
Apr 07 13:20:54 hug cloudflare-ddns[21430]: "

@zaanposni
Copy link
Contributor

Ah, I believe newlines must be stripped!

Yeah, I also thought about that. Can you open a new issue, as this is not directly connected to "Occasional timeout with api.ipify.org"

@Snuggle
Copy link
Contributor Author

Snuggle commented Apr 7, 2020

Oops! A tiny bit too late, I've proposed and tested a fix in PR #43. Would you still like a new issue opened?

@zaanposni
Copy link
Contributor

I am not sure what would be best practice. Guess we can live without a new issue 😄.
I reviewed your change. Please respond there.

LINKIWI pushed a commit that referenced this issue Apr 7, 2020
* Strip trailing whitespace from IP addresses.

This fixes #39, after another bug was introduced by the addition
of more ext. IP address sources.

* Strip trailing whitespace earlier!
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants