PyODBC : can't open the driver even if it exists - python

I'm new to the linux world and I want to query a Microsoft SQL Server from Python. I used it on Windows and it was perfectly fine but in Linux it's quite painful.
After some hours, I finally succeed to install the Microsoft ODBC driver on Linux Mint with unixODBC.
Then, I set up an anaconda with python 3 environment.
I then do this :
import pyodbc as odbc
sql_PIM = odbc.connect("Driver={ODBC Driver 13 for SQL Server};Server=XXX;Database=YYY;Trusted_Connection=Yes")
It returns :
('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0' : file not found (0) (SQLDriverConnect)")
The thing I do not undertsand is that PyODBC seems to read the right filepath from odbcinst.ini and still does not work.
I went to "/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0" and the file actually exists !
So why does it tell me that it does not exist ?
Here are some possible clues :
I'm on a virtual environment
I need to have "read" rights because it's a root filepath
I do not know how to solve either of these problems.
Thanks !

I also had the same problem on Ubuntu 14 after following the microsoft tutorial for SQL Server Linux ODBC Driver.
The file exists and after running an ldd, it showed there were dependencies missing:
/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.20' not found (required by /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0)
/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: versionCXXABI_1.3.8' not found (required by
after searching for a while I found its because Ubuntu's repo didnt have GLIBCXX on version 3.4.20, it was at 3.4.19.
I then added a repo to Ubuntu, updated it and forced it to upgrade libstdc++6
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libstdc++6
Problem solved, tested with isql:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
After that I tried testing using pdo_odbc (PHP), it then gave me the same driver not found error.
To solve this I had to create a symbolic link to fix libodbcinst.so.2:
sudo ln -s /usr/lib64/libodbcinst.so.2 /lib/x86_64-linux-gnu/libodbcinst.so.2

I had the same problem 'file not found (0) (SQLDriverConnect)' on MAC OS with the following code
cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=myServerIP,1433;DATABASE=myDBName;UID=sa;PWD=dbPassword')
after googling for two days, I cannot fix the issue even modify the freetds.conf, odbcinst.ini and odbc.ini
finally, I found the solution via replacing DRIVER value
cnxn =
pyodbc.connect('DRIVER={/usr/local/lib/libmsodbcsql.13.dylib};SERVER=myServerIP,1433;DATABASE=myDBName;UID=sa;PWD=dbPassword')
My dev environment
MAC OS El Capitan
python 3.6.1 in Anaconda

I found an answer that works for me here. This is for python 2.7 (so may not work for those who are looking for a solution for python 3.x).
The suggested solution is to update libgcc: 4.8.5-2 --> 5.2.0-0
For updating libgcc, use this command
conda update libgcc

The following suggestions may help to solve the problem:
Make sure the drive configuration INI file exists odbcinst -j (check odbcinst.ini).
Make sure the filepath to configured driver from your INI file (run: odbcinst -j) exist and has read and executable permission flags (O_RDONLY|O_CLOEXEC).
If you still got file not found error, despite the file exists, the problem could be related to libgcc version mismatch as per nehaljwani's GitHub comment. The solution is to update your libgcc by running conda update libgcc command.
Related: ODBC Driver 13 for SQL Server can't open lib on pyodbc while connecting on AWS E2 ubuntu instance.
For macOS, see: Installing ODBC via HomeBrew.

Maybe it is a bit late, but I leave this scripts that worked for me.
My problem was the same as yours and I tested all the options such as changing the driver location, making a symbolic link, modify /etc/*.ini files, etc... nothing worked.
My problem, running python 3.6, pyodbc package in a docker container from alpine was the library libssl1.0.0
Here you will find my installation script for pyodbc Debian 8 (alpine) docker image using the driver v13
DRIVER={ODBC Driver 13 for SQL Server}
The command I run for database connection was:
import pyodbc
connection_string = 'DRIVER={ODBC Driver 13 for SQL Server};'
connection_string += 'SERVER={0};DATABASE={1};UID={2};PWD={3};'.format(host,dbname,user,pwd)
connection = pyodbc.connect(connection_string)

I solve this problem after installing libssl1.0.0.
First, I setup my connection string in this way:
cnxn = pyodbc.connect('DRIVER={/usr/local/lib/libmsodbcsql.13.dylib};
SERVER=myServerIP,1433;DATABASE=myDBName;UID=sa;PWD=dbPassword')
Then, I installed libssl1.0.0:
echo "deb http://security.debian.org/debian-security jessie/updates main" >> /etc/apt/sources.list
apt-get install libssl1.0.0
Finnaly, I setup the locales:
apt-get -y install locales
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
After doing these steps, my python module was able to find and connect to database.

had the same issue once..
1.try conda update libgcc(this is because pyodbc installed through pip and conda look for different versions of the file..)..this might have been fixed .....
link:https://github.com/ContinuumIO/anaconda-issues/issues/1639
look for nehaljwani answer .
2.also check the version number of the odbc file correctly in /etc/odbcinst.ini and /etc/odbc.ini ...names should match and also the driver path.

Had the same problem on a Mac mini M1 with macOS Mavericks. After installing the driver 18 from Microsoft which supports ARM it still did not work.
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18
However isql on the commandline was able to connect to the database.
isql -v -k "DRIVER={ODBC Driver 18 for SQL Server};SERVER=<MYSERVERNAME>;PORT=<MYPORT>;DATABASE=<MYDATABASE>;UID=<USERNAME>;PWD=<PASSWORD>"
Finally what did the trick was to uninstall pyodbc and install it again.
python -m pip uninstall pyodbc
python -m pip install pyodbc

Related

It returnes problem with mysqldb in python. I don't understand where is the problem [duplicate]

I am trying to connect to a MySQL server with python connector. I created a new user lcherukuri with the authentication plugin mysql_native_password.
But I got the error
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
Can someone help me?
import mysql.connector
cnx = mysql.connector.connect(user='lcherukuri', password='password',
host='127.0.0.1',
database='test')
cnx.close()
I had the same problem and passing auth_plugin='mysql_native_password' did not work, because I accidentally installed mysql-connector instead of mysql-connector-python (via pip3). Just leaving this here in case it helps someone.
Per Caching SHA-2 Pluggable Authentication
In MySQL 8.0, caching_sha2_password is the default authentication plugin rather than mysql_native_password.
You're using mysql_native_password, which is no longer the default. Assuming you're using the correct connector for your version you need to specify the auth_plugin argument when instantiating your connection object
cnx = mysql.connector.connect(user='lcherukuri', password='password',
host='127.0.0.1', database='test',
auth_plugin='mysql_native_password')
From those same docs:
The connect() method supports an auth_plugin argument that can be used to force use of a particular plugin. For example, if the server is configured to use sha256_password by default and you want to connect to an account that authenticates using mysql_native_password, either connect using SSL or specify auth_plugin='mysql_native_password'.
This question is already answered here and this solution works.
caching sha2 password is not supported mysql
Just try this command :
pip install mysql-connector-python
None of the above solution work for me. I tried and very frustrated until I watched the following video:
https://www.youtube.com/watch?v=tGinfzlp0fE
pip uninstall mysql-connector work on some computer and it might not work for other computer.
I did the followings:
The mysql-connector causes problem.
pip uninstall mysql-connector
The following may not need but I removed both connector completely.
pip uninstall mysql-connector-python
re-install mysql-conenct-python connector.
pip install mysql-connector-python
I also got a similar error
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\authentication.py", line 191, in get_auth_plugin
"Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
You have probably installed mysql-connector instead of mysql-connector-python. So you need to install it again for python3:
pip3 install mysql-connector-python
I had this same issue but my resolution was different because this didn't completely work.
I found this on a GitHub forum - copy and paste this into your terminal. You don't have to change your password; it can be the exact same.
ALTER USER 'root'#'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '{NewPassword}';
check your settings using this
select Host,User,plugin from mysql.user;
pip3 install mysql-connector-python did solve my problem as well. Ignore using mysql-connector module.
Modify Mysql encryption
ALTER USER 'lcherukuri'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Use pip install mysql-connector-python
Then connect like this:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost", #hostname
user="Harish", # the user who has privilege to the db
passwd="Harish96", #password for user
database="Factdb", #database name
auth_plugin = 'mysql_native_password',
)
pip install -U mysql-connector-python this worked for me, if you already have installed mysql-connector-python and then follow https://stackoverflow.com/a/50557297/6202853 this answer
I realized that I install mysql-connector instead of mysql-connector-python so run these commands in the terminal
pip3 uninstall mysql-connector
pip3 install mysql-connector-python
You can go to Settings->Project->Project Interpreter and here install latest version of mysql-connector-python package. In my case it was mysql-connector-python 8.0.15.
To have a more permanent solution without going through your code and modifying whatever needs to be modified:
Per MySQL 8 documentation, easiest way to fix this is to add the following to your MySQL d file -> restart MySQL server.
This worked for me!
If your MySQL installation must serve pre-8.0 clients and you encounter compatibility issues after upgrading to MySQL 8.0 or higher, the simplest way to address those issues and restore pre-8.0 compatibility is to reconfigure the server to revert to the previous default authentication plugin (mysql_native_password). For example, use these lines in the server option file:
[mysqld]
#add the following file to your MySQLd file
default_authentication_plugin=mysql_native_password
Please install below command using command prompt.
pip install mysql-connector-python
I was facing the same error for 2 days, then finally I found a solution. I checked for all the installed connectors using pip list and uninstalled all the connectors. In my case they were:
mysql-connector
mysql-connector-python
mysql-connector-python-rf
Uninstalled them using pip uninstall mysql-connector and finally downloaded and installed the mysql-connector-python from MySQL official website and it works well.
For those who couldn't work out because they installed mysql-connector first, I did the following:
1.First on CMD go to the path of 'pip'
2.Use 'pip list' command
3.There would be three packages installed namely six, protobuf and mysql-connector
4.Uninstall each of them separately
5.Now freshly install the mysql-connector-python module
This worked out for me
Install mysql connector using the below command.
pip install mysql-connector-python-rf
Use the command to set the privileges.
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY
'very_strong_password';
FLUSH PRIVILEGES;
Use the python command to connect to mysql database
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="very_strong_password",
auth_plugin='mysql_native_password')
If you are looking for the solution of following error
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Acces
s is denied: 'D:\softwares\spider\Lib\site-packages\libmysql.dll'
Consider using the --user option or check the permissions.
The solution:
You should add --user if you find an access-denied error.
pip install --user mysql-connector-python
paste this command into cmd and solve your problem
This seems to be a problem with the mysql-connector package. Uninstall and install the mysql-connector-python package instead.
sudo pip uninstall mysql-connector
sudo pip install mysql-connector-python
Alternatively, you could use the mysql-connector package with auth_plugin variable shown the following python code
mysql.connector.connect(host='localhost',port="3306",user='user',password='pass',database='dbname',auth_plugin='myql_native_password')
I think in either case, you also need to setup your SQL database user with the mysql_native_password
alter user 'user'#'localhost' identified with mysql_native_password by 'password';
I ran into the same problem as well.
My problem was, that I accidentally installed the wrong connector version.
Delete your currently installed version from your file system (my path looks like this: C:\Program Files\Python36\Lib\site-packages) and then execute
"pip install mysql-connector-python".
This should solve your problem
i try to resolve this error and finally install PyMySQL instead of mysql library
and it's working properly.
thanks.
I had an almost identical error:
Error while connecting to MySQL: Authentication plugin 'caching_sha2_password' is not supported
The solution for me was simple:
My db username/password creds were incorrect. The error was not descriptive of the problem, so I thought I would share this in case someone else runs into this.
I uninstalled mysql-connector (I installed following tutorial on w3schools tutorial) and installed mysql-connector-python instead. It worked.
Using MySql 8 I got the same error when connecting my code to the DB, using the pip install mysql-connector-python did solve this error.
This did the trick for me:
pip install cryptography
if you are looking for connection url or connection string with correct plugin ; then following worked for me
url = 'mysql+mysqlconnector://%s:%s#%s:%s/%s?auth_plugin=mysql_native_password' % (settings['user'], settings['password'], settings['host'], settings['port'], settings['database'])
It failed with MySQL server version 8.0, but worked with the version 5.7.33
The solution is to use MySQL version 5.7.33
pip install mysql-connector-python , i hope it work

How to install GDAL Python Bindings for Postgres.app

I installed the latest Postgre.app version Version 2.5.6 (139) Universal version for my new MacBook Pro M1. After setting up the CLI tools, I am able to access all gdal binaries that come bundled like gdalinfo.
However I also need to install the python bindings to use cli utilities like gdal2tiles.py. What's the right way to go about installing these so they work with the rest of gdal bundled with latest Postgress.app?
Current version bundled with Postgres.app is
➜ gdalinfo --version
GDAL 3.3.3, released 2021/10/25
Postgres.app installs GDAL binaries at:
/Applications/Postgres.app/Contents/Versions/latest/bin and currently has the following bundled:
clusterdb ecpg gdal_translate gdalinfo gdaltindex invproj pg_amcheck pg_ctl pg_resetwal pg_verifybackup proj vacuumdb
createdb gdal-config gdal_viewshed gdallocationinfo gdaltransform nearblack pg_archivecleanup pg_dump pg_restore pg_waldump psql vacuumlo
createuser gdal_contour gdaladdo gdalmanage gdalwarp ogr2ogr pg_basebackup pg_dumpall pg_rewind pgbench raster2pgsql
cs2cs gdal_create gdalbuildvrt gdalmdiminfo geod ogrinfo pg_checksums pg_isready pg_test_fsync pgsql2shp reindexdb
dropdb gdal_grid gdaldem gdalmdimtranslate initdb ogrtindex pg_config pg_receivewal pg_test_timing postgres shp2pgsql
dropuser gdal_rasterize gdalenhance gdalsrsinfo invgeod oid2name pg_controldata pg_recvlogical pg_upgrade postmaster testepsg
I realize there are plenty of ways to install gdal with python bindings using brew and pip, but I am looking to do this the right way while utilizing the core gdal that comes with Postgres.app
Any help is appreciated, Thanks!
Use pygdal, it is made for this exact purpose.
export GDALHOME="/Applications/Postgres.app/Contents/Versions/latest"
pip install pygdal=="`gdal-config --version`.*"

how to read from Kudu to python

I am trying to retrieve data from Kudu. But I am not able to install kudu-python package in anaconda or my server. Can I get some help with it? The documentation on the internet is not really clear.
#Karthik, did you encounter any errors? I just installed kudu-python client on Anaconda on Centos 6.9. There was one gotcha with versioning, but otherwise it was straightforward. The only error I ran into was
kudu/client.cpp:589:30: fatal error: kudu/util/int128.h: No such file or directory
there is a solution for it here: https://community.cloudera.com/t5/Data-Ingestion-Integration/can-not-install-kudu-python/td-p/67496
Otherwise, the steps are:
1. Install kudu client libraries as described on Kudu website (https://kudu.apache.org/docs/installation.html#_install_on_rhel_or_centos_hosts):
wget http://archive.cloudera.com/kudu/redhat/6/x86_64/kudu/cloudera-kudu.repo
sudo mv cloudera-kudu.repo /etc/yum.repos.d/
sudo yum update
sudo yum install kudu kudu-client0 kudu-client-devel
install a bunch of dev dependencies if you don't have them already:
sudo yum install autoconf automake libtool make gcc gcc-c++
install Cython and kudu-python
pip install Cython kudu-python==1.2.0
Once you have this installed, you can find examples in https://github.com/apache/kudu/tree/master/examples/python
i had no ability to install kudu-client (windows os is not supported) so i used the cluster's Impala to get Kudu's tables:
from impala.dbapi import connect
conn = connect('<Impala Daemon>', port=21050)
cursor = conn.cursor()
cursor.execute('SELECT * FROM mytable LIMIT 100')
print(cursor.description) # prints the result set's schema
results = cursor.fetchall()
https://github.com/cloudera/impyla

Connection issues on OSX via pyodbc

I'm trying to write a python app (python 3.5 with pyCharm IDE) that put multiple queries and do math etc... It needs to run on both mac and windows. On windows side because of pymssql won't work i tried pyodbc which worked flawlessly (it's the opposite on mac side). But on the mac side whenever i try to connect with this code:
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=myServerIp;DATABASE=myDatabaseName;UID=myUserName;PWD=myPassword')
cursor = cnxn.cursor()
it gives the error of: pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'odbc.ini' : file not found (0) (SQLDriverConnect)")
Normally i can connect MS SQL from excel or any other query software on mac. I'm using Actual SQL Server driver on system wide.
So please guide me to fix this problem either using Actual SQL Server drivers (which is paid version) or properly configure python or unixodbc (not sure which is the problem). Thank you and regards
PS: I installed both pyodbc, unixodbc and freetds via pip as i followed documentation
Update1:
$ cat $(odbc_config --odbcinstini)
[ODBC]
DEBUG=1
TraceFile=/home/ftp/sqltrace.log
Trace=Yes
[FreeTDS]
Description=MSSQL Driver
Driver=/usr/local/lib/libtdsodbc.so
$ odbc_config --ulen
-DSIZEOF_SQLULEN=8
$ odbc_config --libs
-L/usr/local/Cellar/unixodbc/2.3.2_1/lib -lodbc
$ odbc_config --prefix
/usr/local/Cellar/unixodbc/2.3.2_1
$ odbc_config --odbcinstini
/usr/local/Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini
$ odbc_config --odbcini
/usr/local/Cellar/unixodbc/2.3.2_1/etc/odbc.ini
$ odbc_config --version
2.3.2
uninstalling and installing again with this command fixed the issue:
brew install freetds --with-unixodbc

Psycopg2 Python SSL Support is not compiled in

I am trying to connect to my postgres database using psycopg2 with sslmode='required' param; however, I get the following error
psycopg2.OperationalError: sslmode value "require" invalid when SSL support is not compiled in
Heres a couple details about my system
Mac OS X El Capitan
Python 2.7
Installed psycopg2 via pip
Installed python via homebrew
Here is what I tried to do to fix the problem
brew uninstall python
which python still shows python living in /usr/local/bin/python, tried to uninstall this but couldnt. And heard that this is the python that the OS uses and should not be uninstalled anyways
brew install python --with-brewed-openssl --build-from-source
pip uninstall psycopg2
pip install psycopg2
After doing all of this, the exception still happens. I am running this python script via #!/usr/bin/env python Not sure if it matters, but that is a different directory than the one that which python shows
Since you're installing via pip, you should be using the most recent version of psycopg2 (2.6.1).
After a little digging through the code, it seems that the exception is being thrown in connection_int.c, which directly calls the postgresql-c-libraries to set up the db-connection. The call happens like so:
self->pgconn = pgconn = PQconnectStart(self->dsn);
Dprintf("conn_connect: new postgresql connection at %p", pgconn);
if (pgconn == NULL)
{
Dprintf("conn_connect: PQconnectStart(%s) FAILED", self->dsn);
PyErr_SetString(OperationalError, "PQconnectStart() failed");
return -1;
}
else if (PQstatus(pgconn) == CONNECTION_BAD)
{
Dprintf("conn_connect: PQconnectdb(%s) returned BAD", self->dsn);
PyErr_SetString(OperationalError, PQerrorMessage(pgconn));
return -1;
}
The keywords which were specified in your connect statement to psycopg2.connect() are being handled to that function and errors are returned as OperationalError exception.
The error is actually being generated directly in the postgresql-lib - you may want to check which version you are using, how it was built and, if possible, upgrade it to a version with SSL support or rebuilt it from source with SSL enabled.
The postgresql-docs also state that missing SSL support will raise an error, if the sslmode is set to require, verify-ca or verify-full. See here under sslmode for reference.
The postgres-website lists several ways to install postgres from binary packages, so you might choose one which suits your needs. I'm not familiar with OSX, so I don't have a recommendation what's best.
This question may also be helpful.
You also need to reinstall the psycopg2-module, be sure to use the newly installed lib when rebuilding it. Refer to the linked question (in short, you will need to place the path to pg_config which is included in your new installation to $PATH when running pip install psycopg2).
I had this same error, which turned out to be because I was using the Anaconda version of psycopg2. To fix it, I had adapt VictorF's solution from here and run:
conda uninstall psycopg2
sudo ln -s /Users/YOURUSERNAME/anaconda/lib/libssl.1.0.0.dylib /usr/local/lib
sudo ln -s /Users/YOURUSERNAME/anaconda/lib/libcrypto.1.0.0.dylib /usr/local/lib
pip install psycopg2
Then when you run conda list you'll see psycopg2 installed with <pip> in the far right column. After that, I just restarted Python and everything worked.
The error you are receiving is caused by a problem with Postgres itself, and not psycopg2.
psycopg2.OperationalError: sslmode value "require" invalid when SSL support is not compiled in
The above indicates that the version of Postgres that psycopg2 is built against does not have SSL support compiled in. When you attempt to connect to the running Posgres server with ssl=require it throws this error.
You don't mention how you installed Postgres but since you are using Homebrew for other things, I recommend you also install Postgres the same way:
$ brew update
$ brew install postgresql
The formula for postgresql shows that it depends on openssl and compiles with the --with-openssl flag set. It will also install the neccessary libpq headers. You may need to reinstall psycopg2 after this step to ensure it picks up the correct libraries/version.
Interestingly, there is a bug listed against conda which lists the same error that you report occurring when the conda version of psycopg2 — linked on a system with Homebrew postgres — was installed on a system without, suggesting missing SSL libraries can also trigger this.
I would suggest uninstalling any existing Postgres versions (including any installed via Homebrew) before reinstalling to minimise the risk of the wrong one being used.
As others have said, the error message looks to be coming from Postgres. You can verify this by typing: psql sslmode=require if it gives you a pgsql terminal then ssl works with postgres, if it errors then it doesn't
Try and remove postgres and reinstall with openssl support:
brew uninstall postgres
brew update
brew install postgres --with-openssl
Alternatively, and this is the way I'd suggest, there is a one click installer at http://postgresapp.com that might also make it easier to get it installed. Follow the instructions on the site to get it installed correctly.
When I did it on Yosemite it installed at ~/Library/Application\ Support/Postgres93/var
You'll also want to create a certificate (this could also be where the error is coming from) either from a registrar if this is going to be public facing in the slightest or self signed if it's for a dev/test environment.
openssl req -new -text -out server.req
openssl rsa -in privkey.pem -out server.key
rm privkey.pem
openssl req -x509 -in server.req -text -key server.key -out server.crt
chmod og-rwx server.key
Navigate to your config directory, by default it is: ~/Library/Application\ Support/Postgres93/var
Enable ssl support:
vim postgresql.conf
# change this:
# ssl = on
# to this:
ssl = on
Restart the app and then check ssl with psql "sslmode=require"
If that works then try it through your Python code. If it works with the code above, but not Python then it's definitely a Python code problem that needs to be worked through.
As I can not comment:
Adding to Brideau's answer that this only worked for me after changing my version of Postgres.
brew uninstall postgres
brew update
brew install postgres --with-openssl
Then run the code provided by Brideau and it should work.
If you're using v2.6.1 or v2.6.2 of psycopg2 (like me), the answer was a simple upgrade to v2.7. Reading the release notes for psycopg2, there was a minor fix for SSL albeit it doesn't look particularly relevant.
My setup was as follows:
Mac OS X El Capitan 10.11.6
psycopg2 2.6.2 installed via pip
PostgreSQL installed via Enterprise DB Installer
Running pip uninstall psycopg2 followed by pip install psycopg2 resolved matters.
Try to install psycopg2 from MacPorts
sudo port install py27-psycopg2

Categories