Python connect to firebird docker database - python

I have a mydb.fdb file, how do I can load it into docker container and then connect to it from python. I do the following in my docker-compose:
version: '2'
services:
firebird:
image: jacobalberty/firebird
environment:
ISC_PASSWORD: pass
volumes:
- ./database:/databases
Then I do:
docker exec -it <container-id> bin/bash
And I see my .fdb file inside /databases folder in container, but when I do commands inside container:
cd /usr/local/firebird/bin
./isql
SQL> CONNECT "/databases/mydb.FDB" user sysdba password masterkey;
I received:
Use of database at location /databases/mydb.FDB is not allowed by server configuration
And also I don't understand how to connect to this db via fdb python module. I do:
import fdb
con = fdb.connect(
host='0.0.0.0',
port='3050',
database='mydb.FDB',
user='sysdba',
password='masterkey')
And received:
raise Exception("The location of Firebird Client Library could not be
determined.")

You have two different problems in your question, in the future, please make sure to ask them as separate questions.
As to your first problem, the setup of the Firebird docker image by default expects databases in the location /firebird/data, and explicitly configures Firebird to restrict access to only that location. If you want to use a different location, then you must set the environment variable DBPATH to the correct path. See also issue 12, the Dockerfile and the build.sh of the image. This option doesn't seem to be documented; I have left a comment on that ticket.
As to your second problem, it has two parts. One, you can't use 0.0.0.0 to connect, that is just a shorthand for "all ip addresses of this host", it can only be used when listening for connections, not when connecting. You will need to use 127.0.0.1 or localhost when connecting from the machine running docker.
On top of that, the error suggests that you have no Firebird native client installed. The FDB driver requires fbclient.dll (Windows) or libfbclients.so (Linux). You either need to install the Firebird native client, or switch to pyfirebirdsql, which is a Firebird driver in pure Python (it implements the Firebird protocol in Python).

Related

How do I connect PyCharm to a remote docker registry?

I have pycharm installed on one server and have docker installed on another server.
I wish to connect PyCHarm to docker on the other server.
I have added the IP address and username and password of the server but the test connection fails.
What exactly do I enter into this configuration screen in PyCharm?
Is there a specific format of address I need to use?
Is the IP address/ address url needs to be a public one as specified here
Also keep in mind - the screen you are trying to put your details into is to add a custom docker registry details and not connect your server to another docker server. If you are trying to add a new custom registry, then great! otherwise you might want to have some ssh tunnelling to connect 2 servers.

How to connect to postgres on another server where postgres is on docker?

I can connect to postgres in that way.
On my local machine i run:
ssh name#ip -p 22
input --> password
and then
sudo docker-compose exec postgres bash
after that i have full access to my postgres db.
how can i connect to that DB with python?
I know library like psycopg2, but i didn't found any example how to connect to db which is on another server and with docker ot run.
There are three layers here.
Your local machine.
The server.
The container running the database.
Between each layer, there is a gap. Between
(1) and (2) you have the Internet. Between
(2) and (3) you have docker networking.
Now, what you described in the question is this.
You first cross the (1)-(2) gap with SSH then
you cross the (2)-(3) with the command
sudo docker-compose exec postgres bash.
Now for your question in the comment, according to
docker documentation, docker-compose exec <container-name or id> <command> will
run a command in a container, and sudo elevate your privilege to root account.
Since the command is bash, you essentially open an interactive shell of the
container.
Now this method of crossing the two gaps will work, and you observed, but for
psycopg2 library, it will not.
Again with docker documentation, you can tell docker to eliminate the (2)-(3) gap
for you, this is mainly known as publishing a port. You can tell docker to map
a port on the server to a port on the container, so the (2)-(3) gap can be eliminated.
At this point, the connection to a port on the server will be passed to the container
at the defined port.
Now the only gap you need to cross is just (1)-(2) which can now be done by psycopg2
easily (given that the firewall is allowing inbound connection on that said port).
Now, the detail on how to tell docker to eliminate the (2)-(3) gap is in the answer to Connecting to Postgresql in a docker container from outside. It also show you how you can connect to the database with psql directly from your local machine.

Can't subscribe to local mosquitto broker [duplicate]

I have a virtual machine that is supposed to be the host, which can receive and send data. The first picture is the error that I'm getting on my main machine (from which I'm trying to send data from). The second picture is the mosquitto log on my virtual machine. Also I'm using the default config, which as far as I know can't cause these problems, at least from what I have seen from other examples. I have very little understanding on how all of this works, so any help is appreciated.
What I have tried on the host machine:
Disabling Windows defender
Adding firewall rules for "mosquitto.exe"
Installing mosquitto on a linux machine
Starting with the release of Mosquitto version 2.0.0 (you are running v2.0.2) the default config will only bind to localhost as a move to a more secure default posture.
If you want to be able to access the broker from other machines you will need to explicitly edit the config files to either add a new listener that binds to the external IP address (or 0.0.0.0) or add a bind entry for the default listener.
By default it will also only allow anonymous connections (without username/password) from localhost, to allow anonymous from remote add:
allow_anonymous true
More details can be found in the 2.0 release notes here
You have to run with
mosquitto -c mosquitto.conf
mosquitto.conf, which exists in the folder same with execution file exists (C:\Program Files\mosquitto etc.), have to include following line.
listener 1883 ip_address_of_the_machine(192.168.1.1 etc.)
By default, the Mosquitto broker will only accept connections from clients on the local machine (the server hosting the broker).
Therefore, a custom configuration needs to be used with your instance of Mosquitto in order to accept connections from remote clients.
On your Windows machine, run a text editor as administrator and paste the following text:
listener 1883
allow_anonymous true
This creates a listener on port 1883 and allows anonymous connections. By default the number of connections is infinite. Save the file to "C:\Program Files\Mosquitto" using a file name with the ".conf" extension such as "your_conf_file.conf".
Open a terminal window and navigate to the mosquitto directory. Run the following command:
mosquitto -v -c your_conf_file.conf
where
-c : specify the broker config file.
-v : verbose mode - enable all logging types. This overrides
any logging options given in the config file.
I found I had to add, not only bind_address ip_address but also had to set allow_anonymous true before devices could connect successfully to MQTT. Of course I understand that a better option would be to set user and password on each device. But that's a next step after everything actually works in the minimum configuration.
For those who use mosquitto with homebrew on Mac.
Adding these two lines to /opt/homebrew/Cellar/mosquitto/2.0.15/etc/mosquitto/mosquitto.conf fixed my issue.
allow_anonymous true
listener 1883
you can run it with the included 'no-auth' config file like so:
mosquitto -c /mosquitto-no-auth.conf
I had the same problem while running it inside docker container (generated with docker-compose).
In docker-compose.yml file this is done with:
command: mosquitto -c /mosquitto-no-auth.conf

use psycopg with installed PostgreSQL Database

I would like to get started with working with python and PSQL databases.
The script I have in mind will (at least not at the beginning) run on hosts with an installed PSQL Database, but I want the script to connect remotely to the database.
In fact (for the start):
user hosts: run the script (read xls, convert, manipulate, etc) and write into remote DB
DB Host: this will host the db and gets connections from the user hosts and the "Sync Host"
Sync Host: a cloud service which will connect to the db server to read the databases and do some "magic" with it.
from what I have read, the best python module for PSQL connection is psycopg, but this seems to require an installed PSQL Database, which is something I do not have (and don't want to install) on the user hosts.
At a later stage I will remove the "user hosts" and provide a webinterface for uploading the xls and do the conversion, etc on the db host, but for the beginning I wanted to start as mentioned above.
My questions:
Is my thinking totally wrong? should I start with a central approach (webinterface, etc) right awa
If not, how can I get a PSQL connection method implemented in python without installing a PSQL Database?
All User hosts are Mac OS X, so Python is already installed.
thanks a lot in advance
Andre

Psycopg2 reporting pg_hba.conf error

I've run into a weird situation while trying to use PostgreSQL and Psycopg2. For some reason, every time I attempt to connect to the postgre database via python, I get the following error:
psycopg2.OperationalError: FATAL: no pg_hba.conf entry for host "127.0.0.1", user "steve", database "steve", SSL on
FATAL: no pg_hba.conf entry for host "127.0.0.1", user "steve", database "steve", SSL off
Naturally, I checked pg_hba.conf to see what the issue was, but everything appeared to be configured correctly as far as I can see:
pg_hba.conf:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
In addition, I've found that I can connect to the database via psql as I would expect:
$ psql -U steve -h 127.0.0.1
...
steve=>
Anyone have any ideas as to what could be going on here? Thanks in advance!
Typical explanations include:
You are connecting to the wrong server.
Is the DB server running on the same host as Python does?
You got the wrong port.
Check the server log if you see a connection attempt. You have to log connections for that, of course. See the config parameter log_connections.
You did not reload (SIGHUP) the server after changing pg_hba.conf - or reloaded the wrong cluster (if you have multiple DB clusters).
Use pg_ctl or pg_ctlcluser on Debian and derivatives for that.
Or, on modern Linux installations with systemd (incl. Debian & friends), typically:
sudo systemctl reload postgresql
Or, if there are multiple installations, check with:
sudo systemctl status postgres*
And then realod the one you want with something like:
sudo systemctl reload postgresql#14-main
I recently got into this same issue and I found the solution for this problem.
System:
I have an application server (with these packages installed python, django, psycopg2 and postgres client 9.6.1 (postgresql-9.6.1.tar.gz)), for instance ip address 10.0.0.1(a private address).
And AWS postgres RDS server "aws_rds_host_name" or any database IP address.
Error:
django.db.utils.OperationalError: FATAL: no pg_hba.conf entry for host "10.0.0.1", user "your_user", database "your_db", SSL off
Solution:
While installing the postgres client 9.6.1 source package in application server 10.0.0.1, we have to pass an argument "--with-openssl". I suggest to remove the existing the postgres client and install with below steps.
Download the postgres client source package 9.6.1 (postgresql-9.6.1.tar.gz)
Untar the package postgresql-9.6.1.tar.gz.
./configure --prefix="your_preferred_postgres_path_if_needed" --with-openssl (this '--with-openssl' argument is important to get rid of that error)
make
make install
After successful installation, that error didn't occur when we ran the django project with psycopg2.
I hope this solution helps someone.

Categories

Resources