Developing a desktop application with tkinter, I had an error connecting the database to it.
I'm new to this, I was working locally but I don't know what would happen if I want to share my app with other people. The app would not have access to this database.
I tried to create a database in render.com, once created I made the connection to it through psycopg2 passing the data (hostname, port, db_name, username, and password), but it throws me the error psycopg2:OperationalError.
I know that I am doing something wrong and I have been investigating but I have not been able to find the solution to this. So, when deploying a tkinter app, what database could it use? so that everyone can use the app correctly
I would appreciate any help you can give me, thanks in advance.
Here are the connection settings, which are the same settings from the database created on render.com (I've hidden the password and host):
conn = psycopg2.connect(
dbname='tkinter_app',
user='tkinter_app_user',
password='#############',
host='dpg-cfkimi9mbjsn9eclo3dg-a',
port='5432',
)
And here is the error log:
Traceback (most recent call last):
File "c:\Users\luigi\Desktop\Programacion\tkinter-postgresql-desktop\src\student.py", line 134, in <module>
display_students()
File "c:\Users\luigi\Desktop\Programacion\tkinter-postgresql-desktop\src\student.py", line 27, in display_students
conn = psycopg2.connect(
File "C:\Users\luigi\Desktop\Programacion\tkinter-postgresql-desktop\venv\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not translate host name "dpg-cfkimi9mbjsn9eclo3dg-a" to address: Unknown host
When I created the database, I copied all the configurations as they were, investigating I read that the host should be the External Database URL showed in the rander database configuration, but it didn't work either and it also throws me the error: Unknown Server error
I also try to connect the database in pgAdmin but throws me the same error Unknown host
Related
Python 3.8
Mysql 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
Hi,
I want to connect to a distant mysql server using python's mysqldb connector and paramiko's sshtunnelforwarder.
I can connect to the database remotely without any problems by executing the following:
Connecting to database using mysql password authentication
server = new_ssh_server(config)
with server:
print('Connection', server.local_bind_address)
cnx = MySQLdb.connect(host = '127.0.0.1',
port = server.local_bind_port,
user = config['user'],
passwd = config['password'],
db = config['db'])
Queries work, I can read/write to database, no problem.
I would like to connect to database without supplying mysql password, by using mysql auth_socket authentication method, through ssh.
My attempts at this can be resumed by the following code:
Connecting to database using mysql auth_socket authentication
with server as tunnel:
print('Tunnel:', tunnel.local_bind_address)
cnx = MySQLdb.connect(host = 'localhost', user = 'hillbilly', password = '', db='tutut')#, unix_socket="/tmp/mysql.sock")
res = pd.read_sql('select * from users;', cnx)
print(res)
Which throws the following error:
File "connect_ssh_mysql_auth_socket.py", line 12, in <module>
cnx = MySQLdb.connect(host = 'localhost', user = 'hillbilly', password = '', db='rsotest2')#, unix_socket="/tmp/mysql.sock")
File "...../lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "...../lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
I have and existing mysqld.sock on the distant server that I symlinked to /tmp/mysql.sock, but the error remains. I have also added the next line to /etc/mysql/mysql.conf.d/mysql.cnf:
socket=/run/mysqld/mysqld.sock
But I still get the same error when trying to connect remotely.
Specifying the unix_socket='/run/mysqld/mysqld.sock' to mysqldb connector (commented in Connecting to database using mysql auth_socket authentication) does not fix the issue.
I seem to misunderstand the use of mysql.sock, mysqld.sock.
I was not able to find nor create a mysql.sock socket.
Is what I am trying to do possible? I remember reading somewhere that unix sockets only work locally, does this mean it is not achievable?
Any help/explanation would be appreciated.
(EDIT AND CLOSING)
So this is not possible. Following this thread, auth_socket needs local access to the socket file (usually /tmp/mysql.sock) to run autentication tests, so not accessible through ssh tunneling.
Authentication to remote mysql server using auth_socket plugin is not possible through sshtunnel, as the plugin requires local access to the socket file. See this thread for more information.
I am trying to connect to my Neo4j graph database server from a new machine. I can successfully connect from an older machine but do not wish to use the older one anymore.
I have reduced the problem to a simple script that returns an exception:
from neo4j.v1 import GraphDatabase, basic_auth
auth = basic_auth("username","password")
session = GraphDatabase.driver("bolt://remote.server:7687",auth=auth).session()
statement = """MATCH (a:Protein)
WHERE a.name={name}
RETURN a.Accession"""
tx = session.begin_transaction()
record = tx.run(statement,{'name':"ARCH_HUMAN"}).single()
print record['a.Accession']
session.close()
And the error message is:
File "Test.py", line 10, in <module>
tx = session.begin_transaction()
File "/home/username/anaconda2/lib/python2.7/site-packages/neo4j/v1/api.py", line 432, in begin_transaction
self._connect()
File "/home/username/anaconda2/lib/python2.7/site-packages/neo4j/v1/api.py", line 269, in _connect
self._connection = self._acquirer(access_mode)
File "/home/username/anaconda2/lib/python2.7/site-packages/neo4j/v1/direct.py", line 52, in acquire
raise ServiceUnavailable("Cannot acquire connection to {!r}".format(self.address))
neo4j.exceptions.ServiceUnavailable: Cannot acquire connection to Address(host='remote.server', port=7687)
Port 7687 is open (confirmed via netstat -tulpn and iptables -L), and neo4j is configured to listen to 0.0.0.0:7687. In addition, .neo4j/known_hosts contains an entry for host 0.0.0.0
What's strange is that I get a different error message (neo4j.exceptions.AuthError) if I break the authentication by using an incorrect password. So the connection is being made to check the password, but still I cannot connect with the correct auth.
What's going on?
I too had the same issue and turns out the driver was the issue.
I did some experiments and found out that the last driver that it works for is neo4j-driver==v1.1.0 but the next version neo4j-driver==v1.2.0 it stops working for some reason.
Try uncomment dbms.connectors.default_listen_address=0.0.0.0 And check this
# Bolt connector
dbms.connector.bolt.enabled=true
dbms.connector.bolt.tls_level=OPTIONAL
dbms.connector.bolt.listen_address=:7687
# HTTP Connector. There must be exactly one HTTP connector.
dbms.connector.http.enabled=true
dbms.connector.http.listen_address=:7474
# HTTPS Connector. There can be zero or one HTTPS connectors.
dbms.connector.https.enabled=true
dbms.connector.https.listen_address=:7473
I have a task that asks:
You have two abstract reports made available to you on a PostgreSQL server located at: postgres://candidate.company.org/company
username = candidate password = abc
So I used this code to try connect to the database:
import psycopg2 as db
conn = db.connect(host='postgres://candidate.suade.org/company', database='randomname', user='candidate', password='abc', port='5432')
I received the following error message:
OperationalError: could not translate host name "postgres://candidate.suade.org/suade" to address: Unknown host
My experience of connecting to databases is limited. Can anyone see what I am doing wrong here?
I'm trying to connect to a SQL Server named instance from python 3.4 on a remote server, and get an error.
File "C:\Scripts\Backups Integrity Report\Backup Integrity Reports.py", line 269, in
conn = pymssql.connect(host=r'hwcvcs01\HDPS', user='My-office\romano', password='PASS', database='CommServ')
File "pymssql.pyx", line 636, in pymssql.connect (pymssql.c:10178)
pymssql.OperationalError: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed\n')
Other SQLs are connected without a problem. Also I manage to connect to the SQL using the Management Studio, from the same remote server.
Tried different ports, tried to connect to the host itself rather than the instance, and also tried pypyodbc.
What might be the problem?
For a named instance that looks like this:
myhost\myinstance,1435
You can connect via pymssql with the following:
pymssql.connect(host='myhost', server='myinstance', port='1435', user='user', password='pw')
According to the pymssql documentation on the pymssql Connection class, for a named instance containing database theDatabase, looking like this:
myhost\myinstance
You could connect as follows:
pymssql.connect(host=r'myhost\myinstance', database='theDatabase', user='user', password='pw')
The r-string is a so-called raw string that does not treat the '' as an escape.
import MySQLdb
conn = MySQLdb.connect('localhost', 'user', 'pwd', 'sampledb')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (110)")
How do I connect and what is the issue here? Thank you!
You do not connect to a database on localhost on Go Daddy shared hosting. You will need to locate the correct database host.
Log in to your Account Manager.
Click Web Hosting.
Next to the hosting account you want to use, click Launch.
In the Databases section of the Hosting Control Center, click the MySQL icon.
Click the pencil icon next to the database you would like to get connection strings for.
Your database host name displays in the Host Name field. It will end with "hostedresource.com".
See godaddy's help pages:
http://support.godaddy.com/help/39
import MySQLdb
conn = MySQLdb.connect("host", "user", "password", "database")
host: Get in cPanel "Web sites IP".
user: This user must to have permissions to access (You can add this permission in MySQL Databases menu in cPanel).
database: Name database.
Note: Add permission for your IP in Remote MySQL Menu in cPanel
You can use sqlalchemy
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://user:password#host/database')
conn = engine.connect()