1

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?

3
  • So it works with the dev configuration, but not the production configuration? Commented Apr 8, 2014 at 0:00
  • These may be obvious: Are both instances running as the same user? Are the permissions for the lock/socket location what you expect and what they should be? As a quick test (if safe) change the permissions for these directories to be full access. Also make sure that the UNIX sockets are created with the expected owner/group and permissions when in dev mode. Commented Apr 8, 2014 at 0:33
  • @daveydave400 The connection string is the same in both configs, the difference is how the script is called. I've done a "chmod -R 777 wsgi" and I get an identical error I'm afraid. Commented Apr 8, 2014 at 7:06

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.