Forums

socket error (socket.gaierror exception) when using NTPlib

Hi everyone,

I am getting the following error when trying to connect to NTP servers as described in https://pypi.python.org/pypi/ntplib/0.3.1

Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import ntplib as n
c = n.NTPClient()
response = c.request('europe.pool.ntp.org', version=3)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "ntplib.py", line 265, in request addrinfo = socket.getaddrinfo(host, port)[0] socket.gaierror: [Errno -8] Servname not supported for ai_socktype

Any idea what might happened? Any remedies? Or this can only work on paid account?

Thanks Maurice

I'm afraid that you need a paid account...

That's right. Go on, it's only $5, and we'll give you a refund if you're not 100% happy!

Hi Harry, I had upgraded to the USD 5/month account but I am still getting the same error - https://www.pythonanywhere.com/user/mauricelab/consoles/python2.7/324301/

Any suggestions?

Did you try it in a new console after you upgraded?

Yes Glenn, I did and just did again. Still the same error.

Looks like we have a bug. I think I know what's going on, but we will need to do a full update to get it live. We're hoping to do one of those early to mid next week.

Hi Glenn, Harry, can you file a note when this bug is resolved? Thanks

OK. That fix is in. It works on my account. Let me know if it works for you.

Hi Glenn, it works OK in console. But it does not work in my web2py installation - https://mauricelab.pythonanywhere.com/notalogger/default/ntp_logging

It gives me the following error:

Error ticket for "notalogger" Ticket ID

155.69.203.167.2013-10-25.05-12-25.fa95554b-2df4-40aa-aa59-cfade61a3368 <class 'socket.gaierror'> [Errno -8] Servname not supported for ai_socktype Version web2py™ Version 2.7.4-stable+timestamp.2013.10.14.15.16.29 Python Python 2.7.4: /usr/local/bin/uwsgi (prefix: /usr)

Traceback (most recent call last): File "/home/mauricelab/web2py/gluon/restricted.py", line 217, in restricted exec ccode in environment File "/home/mauricelab/web2py/applications/notalogger/controllers/default.py", line 211, in <module> File "/home/mauricelab/web2py/gluon/globals.py", line 372, in <lambda> self._caller = lambda f: f() File "/home/mauricelab/web2py/applications/notalogger/controllers/default.py", line 175, in ntp_logging response = client.request(server, version=3) File "applications/notalogger/modules/ntplib.py", line 265, in request addrinfo = socket.getaddrinfo(host, port)[0] gaierror: [Errno -8] Servname not supported for ai_socktype

Error snapshot help

<class 'socket.gaierror'>([Errno -8] Servname not supported for ai_socktype)

inspect attributes Exception instance attributes module 'socket' getslice <method-wrapper 'getslice' of gaierror object> str <method-wrapper 'str' of gaierror object> getattribute <method-wrapper 'getattribute' of gaierror object> dict {} sizeof <built-in method sizeof of gaierror object> weakref None init <method-wrapper 'init' of gaierror object> setattr <method-wrapper 'setattr' of gaierror object> reduce_ex <built-in method reduce_ex of gaierror object> new <built-in method new of type object> errno -8 format <built-in method format of gaierror object> class <class 'socket.gaierror'> filename None doc None getitem <method-wrapper 'getitem' of gaierror object> setstate <built-in method setstate of gaierror object> reduce <built-in method reduce of gaierror object> args (-8, 'Servname not supported for ai_socktype') subclasshook <built-in method subclasshook of type object> unicode <built-in method unicode of gaierror object> strerror 'Servname not supported for ai_socktype' delattr <method-wrapper 'delattr' of gaierror object> repr <method-wrapper 'repr' of gaierror object> hash <method-wrapper 'hash' of gaierror object>

Ah. We had to do a bit of hackery to get this in quickly and we overlooked the web servers when we did it. We're hoping to do an upgrade today that will apply it to all of the machines. If we don't get the update done today, we'll be aiming to do it on Monday.

OK. That's deployed and it's working.

Thank you Glenn, it is working now.