I've installed Postgres, mod_wsgi and python3.5 on a centos system. I've tested the connection and it works fine both in the interactive Python shell as well as the development application (it's a Pyramid app so it's the dev server from that).
I'm getting the following error:
postgresql.exceptions.ClientCannotConnectError: could not establish connection to server
CODE: 08001
LOCATION: CLIENT
CONNECTION: [failed]
failures[0]:
socket('127.0.0.1', 5432)
Traceback (most recent call last):
File "/var/www/wsgi/lib/python3.3/site-packages/postgresql/protocol/client3.py", line 136, in connect
self.socket = self.socket_factory(timeout = timeout)
File "/var/www/wsgi/lib/python3.3/site-packages/postgresql/python/socket.py", line 64, in __call__
s.connect(self.socket_connect)
PermissionError: [Errno 13] Permission denied
The above exception was the direct cause of the following exception:
postgresql.exceptions.ConnectionRejectionError: Permission denied
CODE: 08004
LOCATION: CLIENT
CONNECTOR: [Host] pq://username:***#localhost:5432/db_name
category: None
DRIVER: postgresql.driver.pq3.Driver
I spent some time looking at the mod_wsgi documentation and found there is a possible issue with sockets. However, I've already implemented that change (and the corresponding error from apache vanished).
My assumption is that it's a socket error still as the connection sting works fine elsewhere in the same Python install and even within the dev setup.
Can anybody point me in the right direction from here please?
Even if you set the database connect string to an IP address, if it is 127.0.0.1, I have encountered PostgreSQL database connectors which will try and optimise things and connect via the local UNIX socket instead. If the user that your code runs under with mod_wsgi cannot access that UNIX socket for accessing PostgreSQL it will fail with a permissions error.
I can't remember whether it was py-postgresql module that I saw this with, but did hit it a couple of weeks ago with on of the PostgreSQL database modules.
Try replacing 127.0.0.1 with the actual host name or proper IP address.
Related
I have a script that uses Neo4j for tracking user taste preferences on alcohol types. So, basically when a user sets his preferences via an API endpoint the response is buffered to Kafka and I pick it from there. I am getting the following error when trying to read/write to Neo4j via the neo4j python driver:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/ssl.py", line 787, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/lib/python2.7/ssl.py", line 657, in read
v = self.\_sslobj.read(len, buffer)
socket.error: \[Errno 104\] Connection reset by peer
Exception socket.error: error(104, 'Connection reset by peer') in 'neo4j.bolt.\_io.ChunkedInputBuffer.receive' ignored
INFO:UserSettingsProcessorProduction:2018-09-25 13:01:34 Type:<class 'neo4j.exceptions.ServiceUnavailable'> Filename:user_settings_processor.py Line:258 ERROR: Failed to write to closed connection Address(host='54.225.50.91', port=24786)
Strange is that I cannot reproduce it on local but I am getting it often while it is running in
a Docker container. I read somewhere that it could be Docker configuration issue. If the container is private for an example or something like that. I deployed it via AWS / ECS(Elastic Container Service) and it is running on a EC2 instance which is Amazon Linux AMI. If you have any suggestions what may fix it I will be very thankful!
I will keep the thread updated if I find an answer also.
We decided to use GraphQL for communicating with Neo4j and this doesn't seem to be an issue any more. I couldn't find any solution or a clue why actually it is behaving like this, while working perfectly fine on my computer. The service is deployed on a docker container, using ECS.
I am attempting to run a simple command (ls) using the fabric module by following the examples found in the fabric documentation. However, when I attempt to call the run method on a Connection object, I receive
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
import fabric
c = fabric.Connection('host')
c.run('ls')
I have utilized the socket module before, and the error above is generally raised when running socket.gethostbyname(socket.gethostname()) to bind a socket to a machine. However, socket.gethostbyname(socket.gethostname()) runs without error for me.
How can I successfully use fabric to run commands in the shell? As fabric utilizes SSH, are there any SSH configurations needed before using fabric?
I am running fabric on macOS Sierra 10.12.5 on Python 3.7.0
In the Connection constructor, you need to give the real host name.
For instance:
import fabric
c = fabric.Connection('localhost')
c.run('ls')
If the SSH protocole is not configured, you have another error message. For instance:
paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on 127.0.0.1, ::1 or fe80::1%lo0
Ofen, the server name is not enough, you need to add the domain name, for instance myserver.mydomain.com.
I am using a windows XP machine that is using Microsoft SQl Server Enterprise Edition version 8.00.194, SQL-DMO version: 8.00.02 and ODBC version : 03.52.0000. I have another database of MySql on some other machine in the same network and I want to retrieve the data from that database to my XP machine's Sqlserver database. For this purpose I am trying to check whether I can connect to the local machine with my following python script (I use the pymssql library for this purpose):
import pymssql
con1=pymssql.connect(server="localhost:1433",user="XXXX",password="XXXX",database="XXXX")
print con1
con1.close()
I have purposefully removed the original username, password and db name. After running the above script I get the error:
Traceback (most recent call last):
File "D:\py_script_data_1st\1.py", line 9, in <module>
con1=pymssql.connect(server="localhost:1433",user="xxxx",password="xxxx",database="xxxx")
File "pymssql.pyx", line 636, in pymssql.connect (pymssql.c:10178)
OperationalError: (20009, 'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist\nNet-Lib error during Unknown error (10061)\n')
I have searched extensively but did not get any working solution for that error. What I got was to open the port 1433. I have opened the sqlserver.exe instance in my firewall by following the instructions given https://support.microsoft.com/en-us/kb/841251
When I do telnet on port 1433 by using:
telnet localhost 1433
I get error that says could not connect to port 1433.
I would also like to add that the database on which I am working is of a library system. There are two machines on which issues/returns trasactions of the book takes place. So the other machine (which is also a windows XP machine) connects to the server machine using a software that uses netbios-ssn for the communication. I found this fact by using netstat command. Here is the output of that command:
TCP issue:netbios-ssn 192.168.48.45:2211 ESTABLISHED
TCP issue:netbios-ssn 192.168.48.48:3456 ESTABLISHED
I am extremely confused about these facts. I don't understand how can other machine access server's database using netbios-ssn port?
So, I have effectively two questions and solution to any one of them can help me out.
What is the solution for the problem of the python script ?
If the first problem cannot be solved, how can I achieve the connection to the database using netbios-ssn port?
Please help and feel free to ask any further information if you want.
I'm trying to run RabbitMQ Python tutorial but with sender on virtualbox host machine and receiver and queue on virtualbox guest machine. So I modified mentioned send.py code by only replacing localhost with 192.168.1.5. When I run it, i receive following error:
...
File "/home/damian/.virtualenvs/kivy_1.9/local/lib/python2.7/site-packages/pika/adapters/base_connection.py", line 153, in _check_state_on_disconnect
raise exceptions.ProbableAuthenticationError
pika.exceptions.ProbableAuthenticationError
rabbitmq-server seems to be running, because when I stop it send.py gives me:
...
File "/home/damian/.virtualenvs/kivy_1.9/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 301, in _adapter_connect
raise exceptions.AMQPConnectionError(error)
pika.exceptions.AMQPConnectionError: Connection to 192.168.1.5:5672 failed: [Errno 111] Connection refused
which makes perfect sense.
How to fix that ProbableAuthenticationError?
Host machine is Debian 7 with Python 2.7.3 and pika 0.9.14, guest is Ubuntu 15.04 with rabbitmq-server 3.4.3-2
This is because you are trying to authenticate using the username and password guest remotely. Starting with RabbitMQ 3.3 you need to create a new account to use remotely, and guest/guest can only be used locally.
This is taken from the change log here.
25603 prevent access using the default guest/guest credentials except via localhost since (1.0.0)
It's possible to modify the RabbitMQ configuration to allow remote access using the guest account, by removing guest from loopback_users, but it's recommended to create a new user to follow best practices.
[{rabbit, [{loopback_users, []}]}].
I am using the ftplib module and want to connect to FTP on my localhost. I am using the following code example:
import ftplib
f = ftplib.FTP()
f.connect("localhost")
f.login()
ls=[]
f.retrlines('MLSD',ls.append)
for entry in ls:
print entry
It gives me a socket.error: [Errno 61] Connection refused
How do i connect to my localhost and what am i doing wrong? Eventually i would want to send files from a client code to server code using ftplib, both running on the same machine. This is for a project, i know in reality you wouldn't have both on the same machine.
I am guessing the socket.error exception occurs on line 3, where you have connect().
Connection refused indicates that the operating system or the firewall rejected the connection. The most likely reason is that you don't actually have an FTP server running on your local machine.
You didn't say whether you do or you don't, and you didn't say what operating system you're using. But by default, operating systems don't come with an FTP server installed and running. So you need to install a compatible FTP server. A good one to consider is FileZilla Server.