Python mariadb module does not connect to database on network - python

I am trying to connect to a mariadb-database on my local network. using Python.
import mariadb
cursor = mariadb.connect(host='192.168.178.77', user='someuser', password='somepass', db='temps')
Output is:
Traceback (most recent call last):
File "/Users/localuser/PycharmProjects/SQL/main.py", line 20, in <module>
cursor = mariadb.connect(host='192.168.178.77', user='someuser', password='somepass', db='temps')
File "/Users/user/.conda/envs/SQL/lib/python3.10/site-packages/mariadb/__init__.py", line 142, in connect
connection = connectionclass(*args, **kwargs)
File "/Users/localuser/.conda/envs/SQL/lib/python3.10/site-packages/mariadb/connections.py", line 86, in __init__
super().__init__(*args, **kwargs)
mariadb.OperationalError: Can't connect to server on '192.168.178.77' (60)
I can connect via Pycharms Database functionality and send SQL Statements.
I also can use DB management tools from that very host and use data without any issue.
It even works from my phone.
This code is the only place where I get an error.
OS is MacOS13.0.1
Thank You!

This happens due to a bug in MariaDB Connector/C. (Issue CONC-612).
The issue was fixed in C/C Version 3.3.3 - which is available via brew:
After
brew update
brew upgrade mariadb-connector-c
connection should work as expected.

I've got the same problem recently. Add port variable and check other. If doesn't help, try mysql-connector-python it works similar. Or install mariadb connector manually

Related

Stuck with a MySQLdb SSL connection error in Python2.7

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

Instal postgres sql in windows 10

I try to install the latest version of postgres sql using the latest version and the recommended set up.
However when I open the pg adming I receive this error.
Python Path: "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\python.exe"
Runtime Config File: "C:\Users\User\AppData\Roaming\pgadmin\runtime_config.json"
pgAdmin Config File: "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\config.py"
Webapp Path: "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgAdmin4.py"
pgAdmin Command: "C:\Program Files\PostgreSQL\13\pgAdmin 4\python\python.exe C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgAdmin4.py"
Traceback (most recent call last):
File "../web/pgAdmin4.py", line 98, in <module>
app = create_app()
File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgadmin\__init__.py", line 347, in create_app
if not os.path.exists(SQLITE_PATH) or get_version() == -1:
File "C:\Program Files\PostgreSQL\13\pgAdmin 4\web\pgadmin\setup\db_version.py", line 19, in get_version
return version.value
AttributeError: 'NoneType' object has no attribute 'value'
Any help on how to fix it?
After trying all the other suggestions without success, it finally worked for me now, with the way suggested here: Get fatal error: server could not be contacted when running pgAdmin4. 'NoneType' object has no attribute 'value'
Install the newest version of the standalone pgAdmin from https://www.pgadmin.org/download/pgadmin-4-windows/
(you can do the installation additionally to the existing bundled version, without having to remove anything before)
Delete the C:\Users\your_username\AppData\Roaming\pgadmin folder
(I restarted the postgres service once again)
Run the new pgAdmin as Administrator - it works!
Several people report that, from then on, even the old bundled version of pgAdmin works fine!
I resolved in this way:
I removed PGadmin from "Application Stack Builder"
download last version v4 5.2 (pgAdmin 4 v5.2 (released April 22, 2021)
installed...
lunched like admin... (error as usual)
clean-up folder C:\Users\XXXXX\AppData\Roaming\pgadmin (opsssss)
lunched like admin... All ran successfully!
Using all in one PGadmin with Application Stack gave me an usual error bind to some pyton or configuration file
Alen
I had a lot of trouble launching pgAdmin. Several solutions are there.
Try an older version of pgAdmin. The latest version might have unresolved issues.
Go to %APPDATA% (C:\Users{{your username}}\AppData\Roaming) folder and delete the pgadmin folder and run again.
go to environment variables (search environment on search bar) -> advanced, the click on Environment Variables. On System Variables click on path and set a new path for C:\Program Files\PostgreSQL\13\bin (the address might vary on your PC)

SASL error when trying to connect to hive(hue) by python from my PC - Windows10

Need your help!
I read all the documentation that I found on the internet (StackOverflow, Github, etc.), but nothing helped.
I am trying to connect to hive(hue) by python from my PC, my script is:
When I run this code I got this error message:
Traceback (most recent call last):
File "C:/Users/myuser/Documents/Python/testing.py", line 6, in <module>
cursor = hive.connect('myconnect', port=10000, username='root').cursor()
File "C:\Users\myuser\AppData\Local\Continuum\anaconda3\lib\site-packages\pyhive\hive.py", line 94,
in connect
return Connection(*args, **kwargs)
File "C:\Users\myuser\AppData\Local\Continuum\anaconda3\lib\site-packages\pyhive\hive.py", line
192, in __init__self._transport.open()File
"C:\Users\myuser\AppData\Local\Continuum\anaconda3\lib\site-packages\thrift_sasl\__init__.py", line
79, in open message=("Could not start SASL: %s" % self.sasl.getError()))
thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start
(-4) SASL(-4): no mechanism available: Unable to find a callback: 2'
My system detailes:
OS: Windows 10 Pro
Python version: Python 3.7.4
Distribution: Anaconda, Inc. on win32
I found a way to work around the problem.
Actions taken:
Installed VirtualBox with Ubuntu OS on my PC.
Run Ubuntu as root.
Installed python, pip3 and the relevant libraries(pyhive, sasl, thrift_sasl, and thrift)
Run my code - works great!
My conclusion that my problem caused due to security(I am not an admin on my station) and windows issues.

isql works but python connection fails

I'm trying to hook up odbc to work on my Mac with python via pyodbc. I've got things set up such that
isql -v <my Connection>
works just file, however when I'm in a python shell and I try:
import pyodbc
pyodbc.connect('DSN=<my Connection>;UID=<username>;PWD=<password>
I get the cryptic:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('HY000', '[] (202) (SQLDriverConnect)')
What can I do to debug this and determine what steps I can take next to get odbc working? Previously, I had odbc installed and was getting "no driver source name" messages in python, and after moving the odbc.ini and odbcinst.ini file to /etc, I now get the error above. Any ideas? Thanks for your time.
Are you trying to connect to SQL Server? Give this a try:
DRIVER={FreeTDS};SERVER=<yourserver.example.com>;PORT=1433;DATABASE=<your DB>;UID=<your username>;<your password>;TDS_Version=7.2;
Hopefully, that'll work for you. The TDS version depends on what version of SQL Server you're using. See here:
http://www.freetds.org/userguide/choosingtdsprotocol.htm
7.2 also works for 2012 + 2014.
Regards,
-Tim

Pymongo Installation & Executing on MacOS

May i know why i couldn't run the pymongo on MacOS? I installed the pymongo with
sudo easy_install pymongo
but i not sure why will i getting this error
conn = Connection(ip)
File "/Library/Python/2.7/site-packages/pymongo-2.4.2-py2.7-macosx-10.8-intel.egg/pymongo/connection.py", line 180, in __init__
File "/Library/Python/2.7/site-packages/pymongo-2.4.2-py2.7-macosx-10.8-intel.egg/pymongo/mongo_client.py", line 269, in __init__
pymongo.errors.ConnectionFailure: could not connect to 192.168.0.1:27017: [Errno 51] Network is unreachable
thus i google and found i haven't initiate the pymongo yet, then i tried to run
mongod
mongo
./mongod
then it returned me command not found. tried to execute this
sudo export PATH=$PATH:/usr/local/mongodb/bin
Anyone know what's happening to my installation and how could i fix it? Thanks.
You have to install the mongodb server for osx: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

Categories