I'm trying to read fdb files in Ubuntu using firebirdsql:
conn = firebirdsql.connect(host='localhost', database='db.fdb',
user='sysdba', password='masterkey', charset='utf8')
But while connecting, it just said Connection refused.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/.local/lib/python3.6/site-packages/firebirdsql/__init__.py", line 94, in connect
conn = Connection(**kwargs)
File "~/.local/lib/python3.6/site-packages/firebirdsql/fbcore.py", line 595, in __init__
self.sock = SocketStream(self.hostname, self.port, self.timeout, cloexec)
File "~/.local/lib/python3.6/site-packages/firebirdsql/socketstream.py", line 46, in __init__
self._sock = socket.create_connection((host, port), timeout)
File "/usr/lib/python3.6/socket.py", line 724, in create_connection
raise err
File "/usr/lib/python3.6/socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
the code works well on Windows Server, but on Ubuntu it can't establish the connection, how can I solve it?
In the comments you indicate you don't have a Firebird server installed on your machine. As there is no server listening on localhost port 3050, you get the connection refused error.
That firebirdsql, the driver you're using, is pure Python doesn't mean it can open database files by itself, it means it doesn't use a native library to establish a connection, but that it implements the Firebird TCP/IP wire protocol in Python. You will need a Firebird server (either localhost or remotely) to connect to.
Also: a server normally won't be able to access files in your home directory.
Related
I'm trying to connect Python from a Mac to a MySql database that is running on a Raspberry Pi 4 with Ubuntu Server LTS 20.04 installed where both machines are on my LAN. Currently I have MySql Workbench on the Mac and am able to access the database via a Standard TCP/IP connection using SSH. No problem accessing the server via the Terminal over SSH or logging into the database in question.
I'm running Python 3.8.5 on the Mac and the latest version of MySQL Server on the Ubuntu Server installed on the RPi4.
The issue comes up when I write the connection code in a Python file, and attempt to run it via the Terminal. Here is the error I am getting (spaces are mine):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 216, in _open_connection
self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Access denied for user '***'#'localhost' (using password: YES)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "testdb1PYTHON.py", line 3, in <module>
mydb = mysql.connector.connect(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/__init__.py", line 264, in connect
return CMySQLConnection(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 80, in __init__
self.connect(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 966, in connect
self._open_connection()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 218, in _open_connection
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user```
In a nutshell
Using Dockers Desktop Community Version 2.0.0.3 (31259) in macOS Mojave I have two containers:
Alpine
MySQL
From the Alpine docker I am not be able to access the mysql server instance that is running on MySQL docker.
In details
On Alpine I am running python2 and python package mysqlclient. This is the configuration file that I use in my python application to access the mysql databases:
dbtype MySQLdb
connect-args {"user":"abe","db":"abe","passwd":"123"}
upgrade
host docker-mysql
port 32779
When I launch python application I see that it is unable to connect to mysqld server, in fact I get following error log:
python -m Abe.abe --config abe-my.conf
Reconnecting after rollback error: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
Reconnecting to database.
Reconnecting after rollback error: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
Reconnecting to database.
Reconnecting after rollback error: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
Reconnecting to database.
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/bitcoin-abe/Abe/abe.py", line 2123, in <module>
sys.exit(main(sys.argv[1:]))
File "/bitcoin-abe/Abe/abe.py", line 2117, in main
store = make_store(args)
File "/bitcoin-abe/Abe/abe.py", line 156, in make_store
store = DataStore.new(args)
File "Abe/DataStore.py", line 3427, in new
return DataStore(args)
File "Abe/DataStore.py", line 191, in __init__
store.initialize()
File "Abe/DataStore.py", line 637, in initialize
store.configure()
File "Abe/DataStore.py", line 944, in configure
config = store._sql.configure()
File "Abe/SqlAbstraction.py", line 643, in configure
sql.configure_ddl_implicit_commit()
File "Abe/SqlAbstraction.py", line 734, in configure_ddl_implicit_commit
if sql._test_ddl():
File "Abe/SqlAbstraction.py", line 741, in _test_ddl
sql.drop_table_if_exists("%stest_1" % sql.prefix)
File "Abe/SqlAbstraction.py", line 712, in drop_table_if_exists
sql._drop_if_exists("TABLE", obj)
File "Abe/SqlAbstraction.py", line 709, in _drop_if_exists
sql.rollback()
File "Abe/SqlAbstraction.py", line 632, in rollback
sql.reconnect()
File "Abe/SqlAbstraction.py", line 305, in reconnect
return sql.conn()
File "Abe/SqlAbstraction.py", line 288, in conn
sql._conn = sql.connect()
File "Abe/SqlAbstraction.py", line 249, in connect
conn = sql._connect(cargs)
File "Abe/SqlAbstraction.py", line 281, in _connect
return sql.module.connect(**cargs)
File "/usr/lib/python2.7/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/MySQLdb/connections.py", line 164, in __init__
super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
How it could be "fixed"?
I saw that the access file is /run/mysqld/mysqld.sock and I found it in the mysql docker, I suppose it should not be a problem to be able to connect the two dockers so that they "see each other", but at the moment I have no idea.
We are using django to call APIs (ubuntu server) that are on 172.20.44.148.
Our code is the following:
import socket
socket.create_connection(('172.20.44.148', 8080), timeout=2)
However, the connection refused.
This is the error we got from apache:
[root#xxx ~]# python /home/something.py
Traceback (most recent call last):
File "/home/something.py", line 3, in <module>
socket.create_connection(('172.20.44.148', 8080), timeout=2)
File "/usr/local/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused
We also tried to ping 172.20.44.148 and we got a response.
Any ideas?
I am trying use Google app engine to deploy my Django and I followed the steps until "Run the Django migrations to set up your models:"
When I type python manage.py makemigrations and run, it just reports cannot connect.
I do not know why I cannot connect to this port. I have closed my firewall and the IP address is 127.0.0.1. Pymysql is installed already but still cannot connect.
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000002ADF1FA38C8>
Traceback (most recent call last):
File "C:\Users\USER\python-docs-samples\appengine\standard_python37\django\env\lib\site-packages\pymysql\connections.py", line 582, in connect
**kwargs)
File "c:\users\user\appdata\local\programs\python\python37\Lib\socket.py", line 727, in create_connection
raise err
File "c:\users\user\appdata\local\programs\python\python37\Lib\socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 無法連線,因為目標電腦拒絕連線。
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([WinError 10061] 無法連線,因為目標電腦拒絕連線。)")
File "C:\Users\USER\python-docs-samples\appengine\standard_python37\django\env\lib\site-packages\pymysql\connections.py", line 629, in connect
raise exc
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([WinError 10061] 無法連線,因為目標電腦拒絕連線。)")
You need to be sure your setting file is filled with the correct db conf:
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': <db_name>,
'USER': <db_username>,
'PASSWORD': <db_password>,
'HOST': 127.0.0.1,
'PORT': 5433,
Then start a proxy connection following this tutorial
My connection command is:
./cloud_sql_proxy -instances=<instance_connection_name>=tcp:5433 -credential_file=<your_credential_file_path>
I set all connection's port to 5433 in my confs because my local postgres db is already listening on the 5432 port.
I am new to paho-mqtt. I was trying to publish a topic using my localhost and I encountered the following error :
Traceback (most recent call last):
File "server.py", line 10, in <module>
client1.connect(host,port,keepalive)
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 768, in connect
return self.reconnect()
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 895, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 111] Connection refused
My python code is below :
import paho.mqtt.client as paho
port=1883
host = "localhost"
keepalive = 60
def on_publish(client,userdata,result):
print("data published \n")
pass
client1= paho.Client("control1")
client1.on_publish = on_publish
client1.connect(host,port,keepalive)
ret= client1.publish("Robot","Robot 1 move_left")
When I run the same code with iot.eclipse.org as host then it works fine. Any help would be highly appreciated.
I was facing the same issue.
The solution was to install a local MQTT broker.
http://www.steves-internet-guide.com/install-mosquitto-linux/
The exposed docker port for mqtt is usually different than 1883.
I use the official eclipse mosquitto docker and the run example on their page is something like:
sudo docker run -it -p 11883:1883 -p 9001:9001 eclipse-mosquitto
therefore the client should connect to port 11883
client.connect(broker_address, 11883)