Problem with mysql connector authenticator - python

I have a problem with a compiled python application. The program runs a GUI with a connection to a MySQL database. At first I was getting the error:
mysql.connector.errors.NotSupportedError: Authentication plugin
'caching_sha2_password' is not supported
The solution I found here, was to add to the connection command:
auth_plugin = 'mysql_native_password'
And my code looked like this:
conn = mysql.connector.connect(host="localhost", user="root", password="Baelca1", auth_plugin='mysql_native_password')
Now when I compile and run it, I get the error:
mysql.connector.errors.NotSupportedError: Authentication plugin
'mysql_native_password' is not supported.
I'm quite frustrated, I've tried several things and none of them work. I uninstalled and reinstalled mysql-connector-python. I changed the mysql-community server settings. Nothing gets the program to work. The application works fine when I run it from the VSCode terminal but not when I convert it to an executable.
If anyone knows how I can fix it, I would be grateful.

Related

Python SQLAlchemy ProgrammingError: Access denied for user 'myuser'#'myhost'

I noticed a weird bug when trying to connect to the mysql database (hosted on AWS) using sqlalchemy and Anaconda distribution of Python.
When I connect in the script run by Spyder IDE everything works fine, but when I run the same script (with the same Python env) in IntelliJ IDE, the access is denied.
My user has all required privilleges.
Has anyone experienced a similar issue?

jupyter-notebook eith oracle connection problem

I have a problem that I've been trying to solve for a very long time and it seems like I'm missing something very basic.
I use a Linux server with Anaconda, Oracle client, Pycharm and jupyter-notebook installed.
I use python scripts in which I write and read data to Oracle DB, and I use the Cx_oracle extension.
The server has several users with a personal username for each and each of them has sudo privileges.
I performed all the installations on the server with sudo privileges.
When I try to connect from the server to Oracle DB I connect properly.
When I connect to Python on the server itself, I connect properly to Oracle DB.
When I connect using Pycharm and I define ORACLE_HOME=/OracleTools/19.0.0/ in the environment variables, I connect properly to the Oracle DB.
My problem starts when I want to use jupyter-notebook
When I try to connect to the DB I get the error -
DatabaseError: Error while trying to retrieve text for error ORA-12715
I noticed when I execute os.environ I see that it is defined for me:
ORACLE_HOME: /OracleTools/19.0.0/bin
and should be
/OracleTools/19.0.0
So I changed using command os.environ['ORACLE_HOME'] = '/OracleTools/19.0.0'
Then I get an error:
DatabaseError: ORA-12715: invalid character set specified
And of course this change is not permanently saved ...
If on the server itself I execute the env command both in the private user and in sudo I see ORACLE_HOME: /OracleTools/19.0.0 and not ORACLE_HOME: /OracleTools/19.0.0/bin
My questions:
Where does the data I get in the os.environ command come from?
How can I edit them permanently ?
Is this even the problem I'm having or should I check something else?
I manage to import cx_oracle, which means that there is no problem of expansion
Thanks!

Cannot connect to MySQL server Azure from python

I've been trying to connect to a MySQL database remotely but I keep getting the error:
2055: Lost connection to MySQL server at 'local.mysql.database.azure.com:3306', system error: 1 [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1045)
Using the exact same connection details I am able to connect to the database through MySQL Workbench and through Node. For some reason the connection won't go through in python.
This user's as not created to require SSL.
I've been trying to figure out the problem but I'm drawing blanks.
Below is my python login block.
config = {
'host':'local.mysql.database.azure.com',
'user':'user#local',
'password':'password',
'database':'random_db'
}
I've been able to connect to a MySQL instance on the Google Cloud Platform with the exact same connection block but it doesn't work for the Azure connection. I've looked for differences between the two platforms which could have caused this and the only thing I could find was that the Azure MySQL version was 5.7.32log while the GCP was 8.0.18.
I am also currently running python 3.7.0, not sure if that changes anything.
Is there another module I could use if that is the problem, or do I need to downgrade something? I have no idea.
According to this 5.7.29 is the latest 5.7 supported so 5.7.32 would give wrong version error.

Flask app fails to render when deploying code to Azure Web with a database connection, but works fine from local server

I have an Azure web app with a Flask template. I want it to connect to a SQL database. I made one. I installed pymssql. For testing purposes I added to the views.py in the root folder:
import pymssql
conn = pymssql.connect(server='mydb.database.windows.net', user='mydbnameadmin#mydb', password='secret', database='mydb')
I first tested locally on my kubuntu box. To make sure I was getting a connection, I entered the wrong password, and the server threw an error. I entered it correctly and the error disappeared. Cool. Also the SQL dashboard on the azure portal reported sucessfull connections. So then I pushed my changes (including updating the requirements.txt) to my github repo and it was sucked into my web application. When I tried running the web app, on the index page:
The page cannot be displayed because an internal server error has
occurred.
After turning on and inspecting the detailed logs all I get it:
HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server error has occurred.
Most likely causes:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
IIS. What's that doing here? I thought MS was trendy and hosted this service on a linux box 0_0
I remove the second line
conn = pymssql.connect(server='mydb.database.windows.net', user='mydbnameadmin#mydb', password='secret', database='mydb')
and the error disappeared. If I run a server locally, which still uses the Azure SQL server, I don't have any issues.
This seems to be the same issue I have:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e20bb2a3-bdbe-4e49-8b92-b36fe50577da/having-trouble-deploying-flask-app-into-azure-with-azure-database?forum=windowsazurewebsitespreview&prof=required
but they say whether they actually got it working with a SQL database...
what do people think?
Thanks
my requirements.txt
alembic==0.7.7
azure==0.11.1
Flask==0.10.1
Flask-Migrate==1.5.0
Flask-Script==2.0.5
Flask-SQLAlchemy==2.0
futures==3.0.3
itsdangerous==0.24
Jinja2==2.8
Mako==1.0.1
MarkupSafe==0.23
pymssql==2.1.1
python-dateutil==2.4.2
six==1.9.0
SQLAlchemy==1.0.8
Werkzeug==0.10.4
wheel==0.24.0
Per my understanding, Azure Web sites are hosted on Windows Server 2012 VM by default, which would not install FreeTDS and also we don't have permission to install it. And the pymssql is based on FreeTDS.
So we can use pyodbc to connect the Azure SQL as a workaround way to handle it in ease.
I was able to successfully connect my Python code to a SQL Database on Azure using the pymssql 2.1 library.
I don't know if this is what is causing the problem but I did include a couple of extra parameters in my connection string... maybe that will help. I specified the driver explicitly and the Encrypt parameter since SSL is always enabled for SQL Azure (I believe)
myConnection = pyodbc.connect('Driver={SQL Server};'
'Server=tcp:1234567.database.windows.net,1433;'
'Database=MyAzureDatabase;'
'Uid=geekgirl#123456;Pwd=abcdef;'
'Encrypt=yes')
If that doesn't work, maybe try adding some error handling around the connect statement to try and get a more specific error message.
Fingers crossed!
I had this problem, but I eventually realized it was because I was using the 64-bit version of Python in Visual Studio, but Azure only supports the 32-bit version.
I was seeing:
DLL load failed: %1 is not a valid Win32 application.
Once I switched to installing and using the 32-bit version I was able to use Flask and pyodbc with no problems.

Python: MySQLdb working great on Linux, not Windows

I have a problem with an application I am writing.
Using a file dialog a user picks a file whose values are added to a database, or at least, that's the idea.
Using the mysqldb module I have made all the usual connections at the beginning of the application:
db = MySQLdb.connect(host, user, passwd, database)
cursor = db.cursor()
And then run a piece of code like this:
cursor.execute("INSERT INTO info (key1, code, note) VALUES ('testkey1', 'testcode1', 'testnote1;")
db.commit()
The funny thing is that if I run this on Linux (Ubuntu 13.10) it works perfect without errors or issues.
Yet when I run this on Windows (tested on XP and 7), it doesn't commit at all. And I don't get an error to signal there was a problem.
It's only when I check the database that I discover nothing happened.
Does anyone know why I might be having this compatibility issue?
Just to add: The database on Windows is an EXACT copy of the one on Linux.
It is now solved, it was such a silly mistake, but in case there are any Linux users that NEVER use Windows and do run into this issue, here is the solution.
First ensure that Xampp is installed on the Windows machine.
Ensure the ports are open and MySQL and Apache are installed through the Xampp application.
After this, open PhpMyAdmin and make sure that the permissions of user of the database server match those entered in the python application.
After this, the application will run exactly like on Linux.
I thought installing MySQL along with MySQL Workbench was the right move, but it turns out it uses the Apache's version.
Thanks to everyone who helped.

Categories

Resources