When I run 'python manage.py runserver', I get:
File
"/Users/myusername/.virtualenvs/dashboard-server-PG7390RB/lib/python3.6/site-packages/django/db/backends/postgresql/base.py",
line 176, in get_new_connection
connection = Database.connect(**conn_params) File "/Users/myusername/.virtualenvs/dashboard-server-PG7390RB/lib/python3.6/site-packages/psycopg2/init.py",
line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync) " to address: nodename nor servname provided, or not known name "rdsaddress.us-east-1.rds.amazonaws.com
This happened when I updated iterm2, but downgrading did not fix it.
I am able to successfully connect to the database using Postico.
I am unable to connect to a similar rds using Django as well.
I deleted my repository and repulled...
Not sure what to do next.
Hard to say without seeing your connection code, but it should look a little like this:
conn = psycopg2.connect("dbname=your_database user=postgres password=xxxx host=127.0.0.1 port=5432")
The error complains about nodename nor servername provided, hence my inclination to look at your connection string.
Related
I am using the following code to create postgresql database using sqlalchemy:
engine=create_engine('postgresql+psycopg2://postgres#localhost/testData')
Base.metadata.create_all(engine)
But it gives me the following error even though I manually created the database in psql:
File "/home/ubuntu/venve/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 376, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/ubuntu/venve/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
sqlalchemy.exc.OperationalError: (OperationalError) FATAL: database "testData" does not exist
Why is this happening?
You need to create the database beforehand, create_all just creates the tables. To create database: sudo -u postgres createdb testData.
How do I resolve this error in my python script:
conn=psycopg2.connect(dbname=dbname, host=host, port=port, user=rsuser, password=password)
File "/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: connection limit "498" exceeded for non-superusers
I am connecting to a Redshift database, and my script was missing the connection close,
but now how to I remove the connections so I can proceed?
Faced similar issue, while making call to Redshift. Reduced batch size and it worked for me.
Try reducing the batch size for your call.
I want to connect MySQL RDS DB using python from raspberrypi.(i want to get seq from MySQL table 'face' using select query.)
and I have an error but i can not fix it.
This is rds mysql connection code:
import rds_config
import pymysql
rds_host = rds_config.rds_host
name = rds_config.rds_user
password = rds_config.rds_pwd
db_name = rds_config.rds_db
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name,
connect_timeout=10)
with conn.cursor() as cur:
cur.execute("select seq from face")
conn.commit()
rds_config:
rds_host='rds endpoint'
rds_port=3306
rds_user='user'
rds_pwd='password'
rds_db='db name'
and This is traceback:
Traceback (most recent call last):
File "getRds.py", line 18, in <module>
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=10)
File "/usr/local/lib/python2.7/dist-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 327, in __init__
self.connect()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 598, in connect
self._request_authentication()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 862, in _request_authentication
auth_packet = self._process_auth(plugin_name, auth_packet)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 933, in _process_auth
pkt = self._read_packet()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 683, in _read_packet
packet.check_error()
File "/usr/local/lib/python2.7/dist-packages/pymysql/protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.InternalError: (1049, u"Unknown database 'bsb-rds'")
i alread added ip address in vpc security group and public access is on.
it was possible to connect through mysql cli or workbench.
can anyone help me?
tl;dr you need to create bsb-rd. Execute this command: create database bsb-rds either with cur.execute() in python or in your favorite sql cli.
If you get this error, good news! You can connect to your RDS instance. This means you have the security group set up right, the host url, username, password and port are all correct! What this error is telling you is that your database bsb-rds does not exist on your RDS instance. If you have just made the RDS instance it is probably because you have not created the database yet. So create it!
Here are two ways to do this
mysql cli
In your terminal run
mysql --host=the_host_address user=your_user_name --password=your_password
Then inside the mysql shell execute
create database bsb-rd;
Now try your code again!
Python with pymysql
import rds_config
conn = pymysql.connect('hostname', user='username', passwd='password', connect_timeout=10)
with conn.cursor() as cur:
cur.execute('create database bsb-rd;')
I came to this page looking for a solution and didn't get it. I eventually found the answer and now share what helped me.
I ran into your exact issue and I believe I have the solution:
Context:
My tech stack looks like the following
Using AWS RDS (MySQL)
Using Flask Development on local host
RDS instance name: "test-rds"
Actual DB Name: test-database
Here is where my issue was and I believe your issue is in the same place:
You are using the AWS RDS NAME in your connection rather than using the true Database name.
Simply changing the DB name in my connection to the true DB name that I had setup via MySQL Workbench fixed the issue.
Other things things to note for readers:
Please ensure the following:
If you are connecting from outside your AWS VPC make sure you have public access enabled. This is a huge "gotcha". (Beware security risks)
Make sure your connection isn't being blocked by a NACL
Make sure your connection is allowed by a Security Group Rule
I've tried a bunch of thinks including trying to specify the UNIX socket to no avail, I'm not running any queries and I haven't even initialized a cursor but I keep getting this error, what gives?
Python Block:
connection = mysql.connect(user = "root", password = None, port = 8080, host = 'localhost', db ='Articles')
Error:
Traceback (most recent call last):
File "/Users/Adrian/Desktop/Python/webcrawl.py", line 10, in <module>
connection = mysql.connect(user = "root", password = None, port = 8080, host = 'localhost', db ='Articles')
File "/Users/Adrian/anaconda3/lib/python3.6/site-packages/pymysql/__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "/Users/Adrian/anaconda3/lib/python3.6/site-packages/pymysql/connections.py", line 699, in __init__
self.connect()
File "/Users/Adrian/anaconda3/lib/python3.6/site-packages/pymysql/connections.py", line 935, in connect
self._get_server_information()
File "/Users/Adrian/anaconda3/lib/python3.6/site-packages/pymysql/connections.py", line 1249, in _get_server_information
packet = self._read_packet()
File "/Users/Adrian/anaconda3/lib/python3.6/site-packages/pymysql/connections.py", line 991, in _read_packet
packet_header = self._read_bytes(4)
File "/Users/Adrian/anaconda3/lib/python3.6/site-packages/pymysql/connections.py", line 1037, in _read_bytes
CR.CR_SERVER_LOST, "Lost connection to MySQL server during query")
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
Edit: I'm running XAMPP 7.2 on MacOSX with port forwarding enabled over SSH (localhost:8080 -> 80) and the opt/lampp volumes are mounted
It's not advisable to use root without password.
In some databases you are forced to set it if you want to connect as root.
You can set any password: dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
Also, 8080 might be the port of your web server, not the mySQL one, try with 3306 port which is the default one for mySQL.
You can open my.cnf file located in the /Applications/XAMPP/xamppfiles/etc/ directory to chech in which port is your database listening.
Also check that the mySQL daemon is running. In mac os X go to /Applications/XAMPP/XAMPP Control in Finder and check that Apache and MySQL are running.
If your MySQL server isn't starting, you may need to set the permissions for it using Terminal with this command:
chmod -R 777 /Applications/XAMPP/xamppfiles/var
To check that your Articles database exists:
mysql -u root -p
USE Articles;
If it's not created;
mysql -u root -p
CREATE DATABASE Articles;
And connect this way:
#!/usr/bin/python
import MySQLdb
connection = MySQLdb.connect(host="localhost",
user="root",
passwd="your pwd",
db="Articles")
We are trying to access the database of Odoo running on 104.154.90.232 through Python. I have used psycopg2 to connect.
My code is like this:
import psycopg2
import sys
import pprint
conn_string = "host='104.154.90.232' dbname='dbname' user='user' password='password'"
print "connecting to the database\n ->%s"%(conn_string)
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
cursor.execute("SELECT * FROM hr_employee")
records = cursor.fetchall()
pprint.pprint(records)
The error is:
Traceback (most recent call last):
File "test.py", line 6, in <module>
conn = psycopg2.connect(conn_string)
File "C:\Python27\lib\site-packages\psycopg2\__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "104.154.90.232" and accepting TCP/IP connections on port 5432?
Can someone help me establish the connection?
As far as i know, the default pg_hba.conf file only allows connections resp. authentification from the local system. You have to define new rules for external access. It's described in the file, how to do that.
Then ofcourse there has to be a correctly configured database user for odoo.