0
  • I have installed Postgres.app and started it.
  • I have pip installed pypyodbc
  • I have copied the hello world lines from the Pypyodbc docs, and received the error below. any ideas what the issue might be?

Here is my code

  from __future__ import print_function
  import pypyodbc
  import datetime
  conn = pypyodbc.connect("DRIVER={psqlOBDC};SERVER=localhost") 

And I receive this error:

File "/ob/pkg/python/dan27/lib/python2.7/site-packages/pypyodbc.py", line 975, in ctrl_err
  err_list.append((from_buffer_u(state), from_buffer_u(Message), NativeError.value))
File "/ob/pkg/python/dan27/lib/python2.7/site-packages/pypyodbc.py", line 482, in UCS_dec
  uchar = buffer.raw[i:i + ucs_length].decode(odbc_decoding)
File "/ob/pkg/python/dan27/lib/python2.7/encodings/utf_32.py", line 11, in decode
  return codecs.utf_32_decode(input, errors, True)
UnicodeDecodeError: 'utf32' codec can't decode bytes in position 0-1:   truncated data

what am I doing wrong?

Do I need to somehow initialize the DB / tables first? it is a weird error if that is the issue.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Dan Oblinger
  • 489
  • 3
  • 15
  • Does Postgres.app actually include an ODBC driver? A quick look at its [home page](http://postgresapp.com/) seems to suggest that it doesn't. – Gord Thompson May 26 '15 at 11:34
  • Gord, there is no problem. On my Fedora I used `yum install postgresql-odbc` and it installs unixodbc and other required packages. For Windows there is separate installer. I use their ODBC driver and I think it is one of the best ODBC drivers I know (I had some problems with Oracle and Informix drivers while PostgreSQL just works). – Michał Niklas Jun 02 '15 at 05:02
  • I think ODBC driver is installed correctly but there is problem with ConnectString. – Michał Niklas Jun 02 '15 at 05:02
  • @MichałNiklas Your tests may not accurately reflect the environment that the asker is working in. From what I gather, Postgres.app is a stand-alone Mac application that provides a PostgreSQL server without having to actually install PostgreSQL. Tests under Linux (or Windows) with a complete PostgreSQL install (and an explicitly installed ODBC driver for PostgreSQL) could conceivably behave quite differently. – Gord Thompson Jun 03 '15 at 15:17
  • @MichałNiklas indeed you are right. I used the standalone installer from Postgres itself. then I pip installed postgresql-odbc. This should work, but I can see the non-odbc Postgres drivers is where most of the community spends its efforts, so I have given up on the odbc path. (still if someone actually solves the problem in the OSX context, I will select that answer for the larger communities knowledge.) thanks all! – Dan Oblinger Jun 03 '15 at 15:35

1 Answers1

0

I copied your code on my Fedora machine and it started when I changed connect string to something like:

conn = pypyodbc.connect("Driver={PostgreSQL};Server=IP address;Port=5432;Database=myDataBase;Uid=myUsername;Pwd=myPassword;")

You can find more connect strings for PostgreSQL and ODBC at: https://connectionstrings.com/postgresql-odbc-driver-psqlodbc/

Michał Niklas
  • 53,067
  • 18
  • 70
  • 114