I'm trying to connect to phoenix using python plugin 'phoenixdb'.
I'm connecting from a server on the same network with phoenix machine.
Here is the code I am using
import phoenixdb
import phoenixdb.cursor
database_url = 'http://datanode4:2181'
try:
conn = phoenixdb.connect(database_url, autocommit=True,user='',password='')
cursor = conn.cursor()
cursor.execute("SELECT * FROM TESTTABLE")
except Exception as e:
print(e)
finally:
conn.close()
I get the following error
phoenixdb.errors.InterfaceError: ('RPC request failed', None, None,
RemoteDisconnected('Remote end closed connection without response'))
Even when I try to use curl, I get 'Empty reply from server'
Can you guys help me?
Related
I try to reach to my remotemysql database with my Python script which worked fine first, now it doesn't connect anymore so I went to remotemysql.com/login.php but it gives an error
Connection failed: SQLSTATE[HY000] [2002] No such file or directory
anyone know if its only for me or if remotemysql.com is having problems?
my code for Python should also be fine.
these are random credentials in my code btw.
try:
conn = mysql.connector.connect(
host='remotemysql.com',
database='thydfc2',
user='thydfc2',
password=os.environ.get('databasepass'))
except Error as e:
print(e)
if conn.is_connected():
mycursor = conn.cursor()```
Wrote a code to create a sql database via Python:
import mysql.connector
from mysql.connector import Error
def create_connection(host_name, user_name, user_password):
connection = None
try:
connection = mysql.connector.connect(
host=host_name,
user=user_name,
passwd=user_password
)
print("Connection to MySQL DB successful")
except Error as e:
print(f"The error '{e}' occurred")
return connection
connection = create_connection("localhost", "phpmyadmin","mhldb2022!")
But I get an error message:
The error '2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (99)' occurred
In order for the database to be created in phpMyAdmin, I installed WAMP.
Access to phpMyAdmin :
localhost/phpmyadmin/
(default login is "root", no password).
Could you help me to solve the problem?
I really can't understand what is wrong here.
I am using a simple python script to connect the postgresql and future will create the table into the postgresql just using the script.
My code is:
try:
conn = "postgresql://postgres:<password>#localhost:5432/<database_name>"
print('connected')
except:
print('not connected')
conn.close()
when I run python connect.py (my file name), it throws this error :
Instance of 'str' has no 'commit' member
pretty sure is because it detects 'conn' as a string instead of database connection. I've followed this documentation (33.1.1.2) but now sure if Im doing it right. How to correct this code so it will connect the script to my postgresql server instead of just detects it as a string?
p/s: Im quite new to this.
You are trying to call a method on a string object.
Instead you should establish a connection to your db at first.
I don't know a driver which allows the use of a full connection string but you can use psycopg2 which is a common python driver for PostgreSQL.
After installing psycopg2 you can do the following to establish a connection and request your database
import psycopg2
try:
connection = psycopg2.connect(user = "yourUser",
password = "yourPassword",
host = "serverHost",
port = "serverPort",
database = "databaseName")
cursor = connection.cursor()
except (Exception, psycopg2.Error) as error :
print ("Error while connecting", error)
finally:
if(connection):
cursor.close()
connection.close()
You can follow this tutorial
I am using a simple python function to connect to a MySQL database.I receive an error saying a variable is referenced before it is assigned, but this would not be the case if the connection had successfully established. Why is the connection failing?
I am using Ubuntu Linux 18.04. I am running xampp 7.3 to host the mySQL and apache servers and am using phpmyadmin to access the database.I am running my code with python 3.
This is my code:
import mysql.connector
from mysql.connector import Error
def connect():
""" Connect to MySQL database """
try:
conn = mysql.connector.connect(host='localhost',
database='myDB',
user='xxx',
password='yyy!')
if conn.is_connected():
print('Connected to MySQL database')
except Error as e:
print(e)
finally:
conn.close()
if __name__ == '__main__':
connect()
And this is the error I receive:
Traceback (most recent call last):
File "01_python-mysql-connect.py", line 23, in <module>
connect()
File "01_python-mysql-connect.py", line 19, in connect
conn.close()
UnboundLocalError: local variable 'conn' referenced before assignment
I am expecting a successful connection to the database. I believe something could be wrong with my configurations but don't know where to start in solving the problem. Thank you.
This line
conn = mysql.connector.connect(host='localhost',
database='myDB',
user='xxx',
password='yyy!')
is failing. So conn never gets a value assigned to it. But you have a try...except...finally block and in the finally clause your code is doing conn.close(). But conn hasn't been assigned because the statement that was supposed to assign it a value failed. That is why you are seeing the message local variable 'conn' referenced before assignment. To discover what is wrong, move the call to close out of the finally clause and put it before the except. You can always move it back later.
If the mysql.connector.connect() call fails, conn will not be assigned, hence the "referenced before assignment" exception.
This is an ideal use case for the contextlib.closing context manager, I think. Try something like this:
from contextlib import closing
try:
with closing(mysql.connector.connect(...)) as conn:
if conn.is_connected():
print('Connected to MySQL database')
except Error as e:
print(e)
This will cleanly and reliably take care of closing your connection for you.
So I am using pymysql to conenct mysql to flask. When I was developing a website on my local computer everything was fine, later when I uploaded my website to digital ocean trying to connect gives me an error:
'NoneType' object is not iterable
The view I get the error in:
#app.route('/test/')
def test_page():
try:
c, conn = connection()
return("okay")
except Exception as e:
return(str(e))
The connection file looks like this:
import pymysql
def connection():
try:
conn = pymysql.connect(host="localhost", port=3306, user="root", passwd="my_password",db="db_name",charset='utf8')
c = conn.cursor()
return conn, c
except Exception as e:
print (str(e))
I am stuck with this problem for like couple of hours, cant find a solution. Thank you in advance.
Your pymysql.connection is trying to connect to a database running on the local machine.
Evidently there is no database on your Digital Ocean server, or if there is it's not accessible on port 3306 with the credentials provided.
Found a mistake. All I need was a fresh reinstall of mysql :)