- gevent version: 1.2.1
- Python version: 3.5.2
- Operating System: Ubuntu 16.04
Description:
In Python 3.2, the socket.getaddrinfo parameter socktype was renamed to type. This change is not reflected in gevent's monkeypatch replacement of this function (gevent._socketcommon.getaddrinfo). As a result, code that calls socket.getaddrinfo, specifying the type parameter as a keyword argument, raises a TypeError, if gevent.monkey.patch_socket was called previously.
I noticed this issue because it affects the smtpd.SMTPServer from the Python standard library. socket.getaddrinfo is called in its __init__ method (source), so trying to create an SMTPServer object under gevent fails with a TypeError.
What I've run:
Error when calling socket.getaddrinfo directly:
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getaddrinfo("127.0.0.1", 80, type=socket.SOCK_STREAM)
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 80))]
>>> from gevent.monkey import patch_socket
>>> patch_socket()
>>> socket.getaddrinfo("127.0.0.1", 80, type=socket.SOCK_STREAM)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: getaddrinfo() got an unexpected keyword argument 'type'
Error when instantiating smtpd.SMTPServer:
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gevent.monkey import patch_socket
>>> patch_socket()
>>> from smtpd import SMTPServer
>>> SMTPServer(("127.0.0.1", 25), None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/smtpd.py", line 658, in __init__
type=socket.SOCK_STREAM)
TypeError: getaddrinfo() got an unexpected keyword argument 'type'
Description:
In Python 3.2, the socket.getaddrinfo parameter
socktypewas renamed totype. This change is not reflected in gevent's monkeypatch replacement of this function (gevent._socketcommon.getaddrinfo). As a result, code that callssocket.getaddrinfo, specifying thetypeparameter as a keyword argument, raises a TypeError, ifgevent.monkey.patch_socketwas called previously.I noticed this issue because it affects the
smtpd.SMTPServerfrom the Python standard library.socket.getaddrinfois called in its__init__method (source), so trying to create an SMTPServer object under gevent fails with a TypeError.What I've run:
Error when calling
socket.getaddrinfodirectly:Error when instantiating
smtpd.SMTPServer: