I have a python script running on an Amazon EC2 instance (linux) that scrapes the data from a source and outputs a pandas dataframe to me. I want to send this dataframe to MySQL on Amazon RDS. But when I run the script, it throws me the following error:
sqlalchemy.exc.InterfaceError: (mysql.connector.errors.InterfaceError) 2026 (HY000): SSL connection error: SSL_CTX_set_tmp_dh failed
Before executing the script on an ec2 instance, I was running it on my local machine and it was working fine. Meaning, I was able to send the data to the RDS scraped by my scraper. But now that I am running the script on EC2, it is showing me SSL connection errors.
I might not have configured the EC2 instance correctly or might have forgotten to install something. I don't work with SSL much, so I'm finding it difficult figuring out how this is supposed to be set up. Any pointers, even obvious ones, will likely help at this stage.
I have tried some of the solutions that i found on stack but none of them worked. This is my code to connect to the database:
def dbConnect():
end_point = xxx
username = xxx
password = xxx
port=3306
global dbname
dbname=xxx
conn = pymysql.connect(end_point, user=username,port=port,passwd=password, db=dbname)
global eng
eng=create_engine('mysql+mysqlconnector://xxx:xxx#xxx:3306')
return dbname,eng
The solution is to downgrade openssl.
conda install openssl=1.0.2p
See this thread for more information:
https://github.com/ContinuumIO/anaconda-issues/issues/10646
Also this other question.
I have something very similar, although I use PuTTy for the SSH to create a port forwared tunnel.
Make sure you have the security groups set up correctly between your EC2 instance and RDS too.
Related
So I'm trying to establish a connection to a remote Oracle Database in python, from a Linux CentOS machine, but I'm getting the error-
cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred.
I'm using a virtual environment to run my code, wherein I have installed the cx-Oracle==8.3.0.
My python version is 3.6.2 and below is my code
import cx_Oracle
username ="username"
password ="password"
tns_dsn = cx_Oracle.makedsn("examplehost.com", 1528, "SID")
connection = cx_Oracle.connect(
username,
password,
tns_dsn)
print(connection.version)
I've also tried
connection = cx_Oracle.connect("username/password#examplehost.com:1528/SID") and possibly many other ways of connecting to the database, all have given me the same error.
I read other similar questions, some said to modify tnsnames.ora which I can't find anywhere on the system, as I'm using a virtual to implement this.
Please let me know where I'm going wrong or if I'm missing something.
Thanks
I have suddenly started getting this error in my SQL client, and I really do not understand what's going on.
[08001] Could not create connection to database server. Index 5 out of
bounds for length 5
The app that I am working on is using Laravel 6, running on Homestead. I can still connect to server DBs, however I now cannot connect to any local DBs. My OS is Ubuntu 20.04 My DB client is Datagrip.
It was working fine until this started, and I haven't changed anything on my OS - I did install the mysql-connector-python package, but in a virtual env. I have uninstalled that and deactivated the venv, but still having the issue.
I am wondering if I've done my virutal env wrong, and the mysql-connector-python package has made an OS change which I'm now unable to fix.
Any help on the matter would be of great help, as I can't find much info about this specific error anywhere.
I was able to connect to the Homestead box using the box's IP Address, default MYSQL port, and the default Homestead DB username and password.
192.168.10.10:3306
username: homestead
password: secret
It should work the same with you as well. I'm also on Ubuntu and using Datagrip.
I am attempting to connect to a remote MySQL DB from a virtual machine (Ubuntu, running on Azure).
When I access the DB from my computer via the command line, I enter:
mysql -u username -h www.foobar.nyc -p
Which prompts me for the password. When I enter the password, it successfully logs me in to the remote db.
Now when I perform the same actions as above, but instead from a remote vm that I have ssh into, I get the following error returned after entering my pw.
ERROR 1129 (HY000): Host 'xxx.xx.xxx.xxx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
Googling this error brings me to: http://dev.mysql.com/doc/refman/5.7/en/blocked-host.html
I'd like to understand why I am getting so many connection errors - is that normal? Is there a setting perhaps with Azure that I need to look into? I know Azure has the endpoints manager. When using the Python mysql library, it reads that errors occurring File "/site-packages/mysql/connector/connection.py", line 418, in _open_connection on self._do_handshake()
What I hope to gain from this question:
Understand why "many" errors are occurring - what is causing this and is receiving such high numbers of errors normal (as some comments in the MySQL documentation I linked to appear to suggest).
Understand the differences that enable the same actions to work from local in command line but not from command line when ssh into remote Azure based vm.
Thanks.
1.Understand why "many" errors are occurring - what is causing this and is receiving such high numbers of errors normal (as some comments in the MySQL documentation I linked to appear to suggest).
Per my experience, you can check the mysql error logs, details on enabling error logs are # How to see log files in MySQL?.
2.Understand the differences that enable the same actions to work from local in command line but not from command line when ssh into remote Azure based vm.
Based on the latest comment you provided, the new created VM was not experiencing the same issue, it may not be an azure platform specific related issue.
I have a problem which seems impossible to me, meaning I am fundamentally misunderstanding something. I've written a simple API using flask (a python library). This api, among other things, connects to a mysql server running on a remote web server. I am using the sqlalchemy library to perform this connection.
The connection string is quite simple. It looks like this:
db =create_engine('mysql+mysqlconnector://{user}:{password}#{host}:{port}/{database}'.format(user=Constants.Sql.USER, password=Constants.Sql.PASS, host=Constants.Sql.HOST, port=Constants.Sql.PORT, database=Constants.Sql.DATABASE))
connection = db.connect()
On my development machine this all works fine. However, when I deploy the api to a different remote machine, it doesn't work. I get the error:
sqlalchemy.exc.ProgrammingError: (ProgrammingError) 1045 (28000): Access denied for user 'user'#'domain' (using password: YES) None None
This doesn't make any sense to me because it is using exactly the same credentials (they are hard coded).
The working environment is a windows machine, the environment throwing the error is ubuntu 14.04. Both the windows and ubuntu machines are remote to the web server on which the database is running, so it can't be some weird localhost thing.
I am totally stumped with this. If anyone could give me some advice I'd really appreciate it!
Maybe the database only accepts connections from a particular IP address. That would explain why same username and password would succeed on one and fail on the other.
GRANT includes IP address information. Look at the MySQL documentation. Or this tutorial:
https://alvinalexander.com/blog/post/mysql/add-user-mysql/
I am trying to connect to a MySQL database on someone else's "machine". When I use Navicat for MySQL, I have no problem connecting to it. I am trying to do the same with Python so that I do not have to use the GUI interface. I know all my info below is correct (even though I swap fake info) -- can anyone spot where I went wrong? The error I get is OperationalError: (2005, "Unknown MySQL server host 'FTP_hostname' (0)")
My code (using paramiko for the SSH):
import MySQLdb
import paramiko
import time
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('SSH_hostname', 22, username='me', password='pswrd')
time.sleep(1)
db = MySQLdb.connect(host="FTP_hostname",
user="root",
passwd="pswrd2",
db="MyDB")
cur = db.cursor()
Again, I put all this into Navicat and connect no problem. Hoping you can help! Thanks!
MySQL, like most databases, by default runs locally and disallows access from outside networks. As such, you cannot connect to it from an external computer.
Navicat, being a software explicitely for remote administration of databases, likely connects via SSH and tunnels the MySQL connection over it. That way it can act as if the database was installed locally, and for the database it looks as if it was accessed locally.
You could try to do the same by creating a tunnel using Paramiko; see also this question.
If you still in need of connecting to a remote MySQL db via SSH I have used a library named sshtunnel, that wraps ands simplifies the use of paramiko (a dependency of the sshtunnel).
You can check my answer in another similar question with some sample code to use it.
db = MySQLdb.connect(host="FTP_hostname",
Would the host not need to be 127.0.0.1 (localhost) as the tunnel is making the MySQL DB local to the machine that the python script is running on?