I tried the following code on Rasppi to connect to NTP server and get the time. But I get OSError [Errorno 101] Network is unreachable.
Code: Select all
import ntplib from datetime import datetime, timezone c = ntplib.NTPClient() # Provide the respective ntp server ip in below function response = c.request('uk.pool.ntp.org', version=3) response.offset # UTC timezone used here, for working with different timezones you can use [pytz library] print (datetime.fromtimestamp(response.tx_time, timezone.utc))
Does anyone know why I get this? I tried it on a Windows PC and it works fine. Windows PC has got python 3.7 and Rasppi has python 3.5. Is it because of the python version?
I am trying to connect to the NTP server for synchronization between multiple python files on different Rasppis, by the way.