Update: This seems to be connected specifically to the an issue with pyinstaller freezing the socket package. Running the following code is fine in python, but after freezing to an exe with pyinstaller it gives the OSError.
import socket
try:
socket.socket()
except OSError as e:
print(e)
Original text:
I'm currently trying to build a python script that queries a mySQL database using mysql.connector. Running the code in python works fine, but when I freeze it using pyinstaller and run the exe I get an OSError: [WinError 10022] An invalid argument was supplied when it tries to run the mysql.connector.connect function.
My code is below:
import mysql.connector
def test(user, password, ip, query):
con = mysql.connector.connect(user=user,
password=password,
host=ip)
cursor = con.cursor()
cursor.execute(query)
rows = cursor.fetchall()
cursor.close()
con.close()
return rows
The full error text is:
Traceback (most recent call last):
File "site-packages\mysql\connector\network.py", line 507, in open_connection
File "socket.py", line 134 in __init__
OSError: [WinError 10022] An invalid argument was supplied
Looking around, the only mysql.connector questions related to pyinstaller I can find are due to import errors while the WinError 10022 questions seem to be about other packages.
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've been trying to connect Python and MySql but I keep getting errors. This is my code:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="kdvis",
password="root")
print (mydb)
And this is the error I'm getting:
Traceback (most recent call last):
File "C:\Users\kdvis\Desktop\flies\11\python\connection1.py", line 9, in <module>
mydb = mysql.connector.connect(
AttributeError: module 'mysql' has no attribute 'connector'
I've reconfigured MySql, gotten a caching_sha2_password error, a sha256 password requires SSL error, an access denied for user#localhost error, tried to change my root password using alter keyword on MySql, and read almost every solution but none worked.
Help would be appreciated very much.
Have you installed mysql as from pip.
If from other source remove it and install it from pip using coomand.
pip install mysql
I have installed anaconda navigator and working in the spyder workbook.
I am getting an error like TTransport exception.
I have installed all the packages like pyhive, sasl, thrift, thrift-sasl. while connecting python to hive, I was getting this error,"Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'".
Is there any packages do I want to install?? As well I am working in windows, so kindly help me with that..
from pyhive import hive
import sasl
import thrift
import thrift_sasl
conn1 = hive.Connection(host="xxxxx", port=00000, username="yyyy")
cur2 = conn1.cursor()
Errors:
conn1 = hive.Connection(host="xxxx", port=00000, username="yyyy")
Traceback (most recent call last):
File "", line 1, in
conn1 = hive.Connection(host="xxxx", port=00000, username="yyyy")
File "C:\Users\sgpbtp02\AppData\Local\Continuum\anaconda3\lib\site-packages\pyhive\hive.py", line 192, in init
self._transport.open()
File "C:\Users\sgpbtp02\AppData\Local\Continuum\anaconda3\lib\site-packages\thrift_sasl__init__.py", line 79, in open
message=("Could not start SASL: %s" % self.sasl.getError()))
TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'
I have this python code:
#!/usr/bin/env python
import pyodbc
from pandas import *
conn = pyodbc.connect("DSN=drill64", autocommit=True)
cursor = conn.cursor()
which on running as a .py file aur running through ipython notebook gives me the below error
Traceback (most recent call last):
File "/home/ubuntu/TestingDrillQuery.py", line 14, in <module>
conn = pyodbc.connect("DSN=drill64", autocommit=True)
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/mapr/drillodbc/lib/64/libmaprdrillodbc64.so' : file not found (0) (SQLDriverConnect)")
[Finished in 0.4s with exit code 1]
On running through terminal python everything works smoothly, any suggestions appreciated.
Ok, I was able to solve it by changing permission to .py file
chmod +x TestingDrillQuery.py
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')