I use mysqldb connect my db server, server'ip is ::1. Code like this:
MySQLdb.connect(host='::1',user='admin',passwd='123456',db='test')
but, I get an error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", line 81, in Connect
File "build/bdist.linux-i686/egg/MySQLdb/connections.py", line 187, in __init__
_mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host '::1' (1)")
I want to know what should I do to allow mysqldb to support IPv6.
Instead of using ::1 for the host, try use localhost.
If that doesn't work, your system likely does not support IPv6. You can find more information about IPv6 support here.
Related
I have to maintain an old website built using Python2.7 that needs to continue working until we've finished creating a completely new version with more modern tools. Now this old website needs access to a remote MySQL database (connection is set up and working correctly), which so far has worked using the following:
import MySQLdb
db = MySQLdb.connect(host=Host,user=User,passwd=Pass,db=DBse)
Now the server has been upgraded from Ubuntu 18.04. to Ubuntu 20.04., and while I managed to install pip and MySQLdb for Python2.7, I now get the following error for the lines above:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2026, 'SSL connection error: unknown error number')
The SSL connection works fine in Python3 or directly from the command line.
Is there anything I can do to make this work?
Locate and add the line skip_ssl in /etc/mysql/my.cnf ( have tried this on MySQL 8.0.29 , Ubuntu 18)
This was the only thing that worked for me.
[mysqld]
skip_ssl
I am trying to connect to a SSH server using the python library paramiko.
The same code worked on the same computer before, but it started to show a warning when trying to connect. I can connect to the SSH server using the same computer and same users via terminal. The python code also works on other computers connected to the same LAN network.
I also tried to restart both pcs and reinstall paramiko with no success.
Following is the code and the warning message presented.
class SSH:
def __init__(self, ip):
self.ssh = SSHClient()
self.ssh.load_system_host_keys()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(hostname=ip ,username='urs',password='pass')
Warning message:
Unknown exception: '_EllipticCurvePublicKey' object has no attribute 'verify'
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 1886, in run
self.kex_engine.parse_next(ptype, m)
File "/usr/local/lib/python3.5/dist-packages/paramiko/kex_ecdh_nist.py", line 47, in parse_next
return self._parse_kexecdh_reply(m)
File "/usr/local/lib/python3.5/dist-packages/paramiko/kex_ecdh_nist.py", line 105, in _parse_kexecdh_reply
self.transport._verify_key(K_S, sig)
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 1748, in _verify_key
if not key.verify_ssh_sig(self.H, Message(sig)):
File "/usr/local/lib/python3.5/dist-packages/paramiko/ecdsakey.py", line 216, in verify_ssh_sig
self.verifying_key.verify(
AttributeError: '_EllipticCurvePublicKey' object has no attribute 'verify'
Do anybody have a suggestion about where the problem might be?
I tried to google and looked for the error here,but couldn't find it anywhere.
Thanks in advance!
I had the exact same error as now. I encountered this error with paramiko version 2.3.0. I downgraded to 2.1.2 and the operation i was doing proceeded normally.
I have not been able to connect to an Azure hosted MSSQL server through pymssql on pythonanywhere.
I have zero previous linux experience, so that is making it harder than it should.
I am trying this sample script provided with the instructions:
host = "123.456.789.012"
username = "yourusername"
password = "yourpassword"
database = "yourdatabasename"
conn = pymssql.connect(host, username, password, database)
cursor = conn.cursor()
But I get this error:
Traceback (most recent call last):
File "pymssql.pyx", line 635, in pymssql.connect (pymssql.c:10734)
File "_mssql.pyx", line 1902, in _mssql.connect (_mssql.c:21821)
File "_mssql.pyx", line 637, in _mssql.MSSQLConnection.__init__ (_mssql.c:6581)
File "_mssql.pyx", line 1630, in _mssql.maybe_raise_MSSQLDatabaseException (_mssql.c:17524)
_mssql.MSSQLDatabaseException: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (my_server_name.database.windows.net:1433)\n')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824)
pymssql.OperationalError: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (my_server_name.database.windows.net:1433)\n')
I figured it had to do with the TDS Version I am running, which I get to be 4.2 by running tsql -C on bash. Here is the output:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
I have tried placing a .freetds.conf file both at home/myuser/ and at home/myuser/my_virtual_env/, but that did not change any behavior. Should I have restarted the bash console or the python console? I did not think so. Here are the file contents:
[global]
tds version = 7.1
[azure]
tds version = 7.4
The other alternative would be to use pyodbc, but that would also involve configuring freetds and then some more, so it looks like there is nothing to be had there.
I should point out that I have pymssql connecting just fine to azure on my win10 machine with the following connection string:
arguments = dict(server=db_server_add, user=db_usn+"#my_server",
password=db_pswd, database=db_name, charset="utf8")
AZURE_ENGINE = create_engine('mssql+pymssql:///', connect_args=arguments)
In Python Anywhere on a free account, it does not allow access to all web addresses. Only addresses from a specific list.
"If you have a paid Python Anywhere plan"
https://help.pythonanywhere.com/pages/MSSQLServer/
I am trying to use pymssql library to connect to the sql server in ubuntu but got the following error. But I tried the same script in the mac and it works.
I think there is a FreeTDS configuration problem in ubuntu but almost tried all of the recommanded methods in the web still no luck so far. Anyone can point me to the right direction?
import pymssql
conn = pymssql.connect(server='blah.database.windows.net',
user='blah',
password='!',
database='database')
cursor = conn.cursor()
cursor.execute('SELECT * FROM table')
data = cursor.fetchall()
print(data)
error:
Traceback (most recent call last):
File "test.py", line 13, in <module>
database='my data base')
File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824)
pymssql.OperationalError: (20002, 'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed\n')
I use ws4py as a websocket server. it can run normally in Windows and Mac, but it runs in linux system raising a TB when websocket clients connect to server. Anybody can tell me how to fix this bug?
[2016-01-06 20:51:43,094] ERROR Failed to receive data
Traceback (most recent call last):
File "/home/yzliu/airtest/env/local/lib/python2.7/site-packages/ws4py/websocket.py", line 300, in once
b = self.sock.recv(self.reading_buffer_size)
File "/home/yzliu/airtest/env/local/lib/python2.7/site-packages/gevent/_socket2.py", line 264, in recv
return sock.recv(*args)
File "/home/yzliu/airtest/env/local/lib/python2.7/site-packages/gevent/_socket2.py", line 73, in _dummy
raise error(EBADF, 'Bad file descriptor')
This is a bug in ws4py, when used with gevent 1.1, as the underlying
socket is closed when WSGI handler returns.
See: https://github.com/Lawouach/WebSocket-for-Python/pull/180/files