Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IPv6 #118

Closed
error10 opened this issue Aug 16, 2012 · 2 comments
Closed

Support IPv6 #118

error10 opened this issue Aug 16, 2012 · 2 comments

Comments

@error10
Copy link

error10 commented Aug 16, 2012

MySQL supports IPv6 with version 5.5, but pymysql has no support for IPv6 and fails with a strange error if you attempt to use an IPv6 address:

  File "connections.py", line 743, in _connect
    raise OperationalError(2003, "Can't connect to MySQL server on %r (%s)" % (self.host, e.args[0]))
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '2001:db8:81:2c::2' (-9)")

I'm no Python expert but I think the problem is that an AF_INET6 socket should be opened when trying to connect to an IPv6 address.

@error10
Copy link
Author

error10 commented May 31, 2013

I've worked around this and added IPv6 support with the following change. The problem is that it raises the minimum Python requirement to version 2.6. To keep compatibility with 2.4, a whole lot of extra code would be needed. Though, I'm not really sure if anybody's even still using 2.4 anymore...

                 if DEBUG: print 'connected using unix_socket'
             else:
-                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-                t = sock.gettimeout()
-                sock.settimeout(self.connect_timeout)
-                sock.connect((self.host, self.port))
-                sock.settimeout(t)
+                sock = socket.create_connection((self.host, self.port), self.connect_timeout)
                 self.host_info = "socket %s:%d" % (self.host, self.port)
                 if DEBUG: print 'connected using socket'

@methane
Copy link
Member

methane commented Sep 29, 2013

@error10 I've merged your patch. Thanks!

czerwingithub pushed a commit to scalyr/PyMySQL that referenced this issue Sep 20, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants