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

tunnel over IPv6 fails (IPv4 working fine) #194

Closed
AceScottie opened this issue Oct 8, 2020 · 1 comment
Closed

tunnel over IPv6 fails (IPv4 working fine) #194

AceScottie opened this issue Oct 8, 2020 · 1 comment

Comments

@AceScottie
Copy link

AceScottie commented Oct 8, 2020

Having some issues with sshtunnel failing to connect when using IPv6. Tested IPv4 working fine.

Error: 08-10-2020,(+0100),23:33:49, sql.create_connection failed
An error occurred while opening tunnels., <class 'sshtunnel.HandlerSSHTunnelForwarderError'>, An error occurred while opening tunnels.,   File "C:\Users\Me\Desktop\patient\SP.py", line 523, in create_connection
  File "C:\Users\Me\Desktop\patient\tunnel.py", line 29, in secure_sql
  File "C:\Python38\lib\site-packages\sshtunnel.py", line 1313, in start
  File "C:\Python38\lib\site-packages\sshtunnel.py", line 1100, in _raise

code:

import sshtunnel
import pymysql
import socket 
class ssh_tunnel:
	def __init__(self, add, passwd, user, port, sql, db, ipv):
		if ipv == 4:
			self.add = add
			self.lba = "127.0.0.1"
		elif ipv == 6:
			self.add = add
			self.lba = "::1"
		self.db = db # sql database name
		self.pw = passwd # sql and ssh password
		self.user = user # sql and ssh username
		self.port = port # ssh port
		self.sqlport = sql # sql port
		self.get_open_port()
		self.server = self.gen_connection()
	def get_open_port(self):
		s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		s.bind(('', 0))
		addr = s.getsockname()
		self.open_port = addr[1]
		s.close()
	def gen_connection(self):
		return sshtunnel.open_tunnel((self.add, self.port), ssh_username=self.user, ssh_password=self.pw, remote_bind_address=(self.add, self.sqlport), local_bind_address=(self.lba, self.open_port))
	def secure_sql(self):
		self.server.start()
		return pymysql.connect(host="localhost", port=self.server.local_bind_port, user=self.user, passwd=self.pw, db=self.db, charset='utf8',  cursorclass=pymysql.cursors.DictCursor)
@pahaz
Copy link
Owner

pahaz commented Oct 25, 2020

could you please provide a reproducible example?
We also have some new release 0.2.0 with ipv6 support. Could you please try to check it?
could you please run your code with sshtunnel.open_tunnel( ..., debug_level=1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants