Calvin Cheng | 10 Jul 06:14 2008

Problem with Successfully Installed Psycopg2

Hi there,

I have been searching for a possible solution but have not been very successful.   I managed to get pyscopg2 installed in cygwin using "easy_install psycopg2" but when I attempt to import it in python shell, this is the error traceback I am getting:

Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "__init__.py", line 60, in <module>

  File "build/bdist.cygwin-1.5.25-i686/egg/psycopg2/_psycopg.py", line 7, in <module>
  File "build/bdist.cygwin-1.5.25-i686/egg/psycopg2/_psycopg.py", line 6, in __bootstrap__
ImportError: No such file or directory
>>>


Any idea what I have done wrong?

Regards,
Calvin

_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
Farhan Ahmad | 13 Jul 21:06 2008

Getting psycopg2 to work in cygwin on Windows Vista

Hi,

I am trying to get psycopg2 to work on Windows Vista through cygwin.  Everything compiles fine, but when I import it python says that it can't findany module by that name.  I have attached the output from a "python -v" session.  Does anyone have any ideas why the system cannot find the _psycopg?  Everything compiled and installed without any issues.

 

Thank you!

Farhan

# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib/python2.5/site.pyc matches /usr/lib/python2.5/site.py
import site # precompiled from /usr/lib/python2.5/site.pyc
# /usr/lib/python2.5/os.pyc matches /usr/lib/python2.5/os.py
import os # precompiled from /usr/lib/python2.5/os.pyc
import posix # builtin
# /usr/lib/python2.5/posixpath.pyc matches /usr/lib/python2.5/posixpath.py
import posixpath # precompiled from /usr/lib/python2.5/posixpath.pyc
# /usr/lib/python2.5/stat.pyc matches /usr/lib/python2.5/stat.py
import stat # precompiled from /usr/lib/python2.5/stat.pyc
# /usr/lib/python2.5/UserDict.pyc matches /usr/lib/python2.5/UserDict.py
import UserDict # precompiled from /usr/lib/python2.5/UserDict.pyc
# /usr/lib/python2.5/copy_reg.pyc matches /usr/lib/python2.5/copy_reg.py
import copy_reg # precompiled from /usr/lib/python2.5/copy_reg.pyc
# /usr/lib/python2.5/types.pyc matches /usr/lib/python2.5/types.py
import types # precompiled from /usr/lib/python2.5/types.pyc
import _types # builtin
# zipimport: found 78 names in /usr/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg
# /usr/lib/python2.5/warnings.pyc matches /usr/lib/python2.5/warnings.py
import warnings # precompiled from /usr/lib/python2.5/warnings.pyc
# /usr/lib/python2.5/linecache.pyc matches /usr/lib/python2.5/linecache.py
import linecache # precompiled from /usr/lib/python2.5/linecache.pyc
import encodings # directory /usr/lib/python2.5/encodings
# /usr/lib/python2.5/encodings/__init__.pyc matches /usr/lib/python2.5/encodings/__init__.py
import encodings # precompiled from /usr/lib/python2.5/encodings/__init__.pyc
# /usr/lib/python2.5/codecs.pyc matches /usr/lib/python2.5/codecs.py
import codecs # precompiled from /usr/lib/python2.5/codecs.pyc
import _codecs # builtin
# /usr/lib/python2.5/encodings/aliases.pyc matches /usr/lib/python2.5/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib/python2.5/encodings/aliases.pyc
# /usr/lib/python2.5/encodings/ascii.pyc matches /usr/lib/python2.5/encodings/ascii.py
import encodings.ascii # precompiled from /usr/lib/python2.5/encodings/ascii.pyc
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) 
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
import psycopg2 # directory /usr/lib/python2.5/site-packages/psycopg2
# /usr/lib/python2.5/site-packages/psycopg2/__init__.pyc matches /usr/lib/python2.5/site-packages/psycopg2/__init__.py
import psycopg2 # precompiled from /usr/lib/python2.5/site-packages/psycopg2/__init__.pyc
dlopen("/usr/lib/python2.5/lib-dynload/datetime.dll", 2);
import datetime # dynamically loaded from /usr/lib/python2.5/lib-dynload/datetime.dll
# /usr/lib/python2.5/decimal.pyc matches /usr/lib/python2.5/decimal.py
import decimal # precompiled from /usr/lib/python2.5/decimal.pyc
# /usr/lib/python2.5/copy.pyc matches /usr/lib/python2.5/copy.py
import copy # precompiled from /usr/lib/python2.5/copy.pyc
# /usr/lib/python2.5/threading.pyc matches /usr/lib/python2.5/threading.py
import threading # precompiled from /usr/lib/python2.5/threading.pyc
import thread # builtin
dlopen("/usr/lib/python2.5/lib-dynload/time.dll", 2);
import time # dynamically loaded from /usr/lib/python2.5/lib-dynload/time.dll
# /usr/lib/python2.5/traceback.pyc matches /usr/lib/python2.5/traceback.py
import traceback # precompiled from /usr/lib/python2.5/traceback.pyc
dlopen("/usr/lib/python2.5/lib-dynload/collections.dll", 2);
import collections # dynamically loaded from /usr/lib/python2.5/lib-dynload/collections.dll
# /usr/lib/python2.5/re.pyc matches /usr/lib/python2.5/re.py
import re # precompiled from /usr/lib/python2.5/re.pyc
# /usr/lib/python2.5/sre_compile.pyc matches /usr/lib/python2.5/sre_compile.py
import sre_compile # precompiled from /usr/lib/python2.5/sre_compile.pyc
import _sre # builtin
# /usr/lib/python2.5/sre_constants.pyc matches /usr/lib/python2.5/sre_constants.py
import sre_constants # precompiled from /usr/lib/python2.5/sre_constants.pyc
# /usr/lib/python2.5/sre_parse.pyc matches /usr/lib/python2.5/sre_parse.py
import sre_parse # precompiled from /usr/lib/python2.5/sre_parse.pyc
# /usr/lib/python2.5/site-packages/psycopg2/tz.pyc matches /usr/lib/python2.5/site-packages/psycopg2/tz.py
import psycopg2.tz # precompiled from /usr/lib/python2.5/site-packages/psycopg2/tz.pyc
dlopen("/usr/lib/python2.5/site-packages/psycopg2/_psycopg.dll", 2);
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/psycopg2/__init__.py", line 60, in <module>
    from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No such file or directory
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] psycopg2.tz
# cleanup[1] site
# cleanup[1] datetime
# cleanup[1] encodings
# cleanup[1] sre_constants
# cleanup[1] threading
# cleanup[1] re
# cleanup[1] collections
# cleanup[1] _codecs
# cleanup[1] zipimport
# cleanup[1] warnings
# cleanup[1] encodings.ascii
# cleanup[1] codecs
# cleanup[1] _types
# cleanup[1] thread
# cleanup[1] signal
# cleanup[1] traceback
# cleanup[1] linecache
# cleanup[1] posix
# cleanup[1] encodings.aliases
# cleanup[1] time
# cleanup[1] exceptions
# cleanup[1] sre_parse
# cleanup[1] decimal
# cleanup[1] sre_compile
# cleanup[1] _sre
# cleanup[1] copy
# cleanup[1] types
# cleanup[2] copy_reg
# cleanup[2] posixpath
# cleanup[2] os.path
# cleanup[2] stat
# cleanup[2] UserDict
# cleanup[2] os
# cleanup sys
# cleanup __builtin__
# cleanup ints: 484 unfreed ints in 10 out of 10 blocks
# cleanup floats: 3 unfreed floats in 1 out of 1 block
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
Daniele Varrazzo | 14 Jul 02:50 2008
Picon

Re: Getting psycopg2 to work in cygwin on Windows Vista

Farhan Ahmad ha scritto:

> I am trying to get psycopg2 to work on Windows Vista through cygwin.  
> Everything compiles fine, but when I import it python says that it can't 
> findany module by that name.  I have attached the output from a "python
> -v" session.  Does anyone have any ideas why the system cannot find the 
> _psycopg?  Everything compiled and installed without any issues.

Did you issue "python setup.py install" in the psycopg directory?

If everything compiled fine, you should have a "_psycopg.dll" in a 
subdirectory under "build", which is not included in the pythonpath. The above 
command should put all the pieces in the proper place.

-- Daniele
Farhan Ahmad | 14 Jul 07:15 2008

Re: Getting psycopg2 to work in cygwin on Windows Vista

Thanks for the reply, Daniele.  Yes, I did.  Looking at the output that I
sent before I did notice that it had a dlopen() call, but the dll does
exist at that path.  I have tried playing around with the permissions in
both Vista and cygwin, but with no luck.

dlopen("/usr/lib/python2.5/site-packages/psycopg2/_psycopg.dll", 2);
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/psycopg2/__init__.py", line 60, in
<module>
    from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No such file or directory

Here are the contents of that directory.

509 psycopg2 $ pwd
/usr/lib/python2.5/site-packages/psycopg2
510 TheBitGuru <at> visionary psycopg2 $ ll
total 416
-rw-r--r-- 1 TheBitGuru None   2774 Jul 13 00:38 __init__.py
-rw-r--r-- 1 TheBitGuru None   2379 Jul 13 12:59 __init__.pyc
-rwxrwxrwx 1 TheBitGuru None 315420 Jul 13 13:17 _psycopg.dll
-rw-r--r-- 1 TheBitGuru None  10138 Jul 13 00:38 errorcodes.py
-rw-r--r-- 1 TheBitGuru None  10511 Jul 13 12:59 errorcodes.pyc
-rw-r--r-- 1 TheBitGuru None   2487 Jul 13 00:38 extensions.py
-rw-r--r-- 1 TheBitGuru None   2410 Jul 13 12:59 extensions.pyc
-rw-r--r-- 1 TheBitGuru None   7396 Jul 13 00:38 extras.py
-rw-r--r-- 1 TheBitGuru None  11038 Jul 13 12:59 extras.pyc
-rw-r--r-- 1 TheBitGuru None   6031 Jul 13 13:42 output.txt
-rw-r--r-- 1 TheBitGuru None   7847 Jul 13 00:38 pool.py
-rw-r--r-- 1 TheBitGuru None   8808 Jul 13 12:59 pool.pyc
-rw-r--r-- 1 TheBitGuru None   2804 Jul 13 00:38 psycopg1.py
-rw-r--r-- 1 TheBitGuru None   3370 Jul 13 12:59 psycopg1.pyc
-rw-r--r-- 1 TheBitGuru None   2973 Jul 13 00:38 tz.py
-rw-r--r-- 1 TheBitGuru None   3502 Jul 13 12:59 tz.pyc
511 psycopg2 $ 

Thanks,
Farhan

On Mon, 14 Jul 2008 01:50:35 +0100, Daniele Varrazzo
<daniele.varrazzo@...> wrote:
> Farhan Ahmad ha scritto:
> 
>> I am trying to get psycopg2 to work on Windows Vista through cygwin.
>> Everything compiles fine, but when I import it python says that it can't
>> findany module by that name.  I have attached the output from a "python
>> -v" session.  Does anyone have any ideas why the system cannot find the
>> _psycopg?  Everything compiled and installed without any issues.
> 
> Did you issue "python setup.py install" in the psycopg directory?
> 
> If everything compiled fine, you should have a "_psycopg.dll" in a
> subdirectory under "build", which is not included in the pythonpath. The
> above
> command should put all the pieces in the proper place.
> 
> -- Daniele
Alejandro Dubrovsky | 18 Jul 09:14 2008

copy_from doesn't handle specifying null character properly

Hi all,

I'll make it short:

cursor.copy_from(somefile, 'sometable')
works in cases where
cursor.copy_from(somefile, 'sometable', null='\\N')
doesn't.  This is in bzr trunk (or whatever head is called in bzr)

It does work with the following:

cursor.copy_from(somefile, 'sometable', null=r'\\N')
or 
cursor.copy_from(somefile, 'sometable', null='\\\\N')

psycopg2 sends the following to postgres (from the debug output):

 ...testsimple FROM stdin USING DELIMITERS ' ' WITH NULL AS '\N'

which postgres sort of interprets as N (eating the escape).  psycopg2
should escape the string before sending it to postgres.

In some possible configurations, this could be a security hole.  If
input from the user is passed to psycopg2 as the null parameter in the
very reasonable assumption that psycopg2 should escape those values,
something like null="'; <malicious code> where '' = '" would likely get
through.

_______________________________________________
Psycopg mailing list
Psycopg <at> lists.initd.org
http://lists.initd.org/mailman/listinfo/psycopg
Federico Di Gregorio | 19 Jul 15:09 2008

Re: copy_from doesn't handle specifying null character properly

Il giorno ven, 18/07/2008 alle 17.14 +1000, Alejandro Dubrovsky ha
scritto:
> Hi all,
> 
> I'll make it short:
> 
> cursor.copy_from(somefile, 'sometable')
> works in cases where
> cursor.copy_from(somefile, 'sometable', null='\\N')
> doesn't.  This is in bzr trunk (or whatever head is called in bzr)
> 
> 
> It does work with the following:
> 
> cursor.copy_from(somefile, 'sometable', null=r'\\N')
> or 
> cursor.copy_from(somefile, 'sometable', null='\\\\N')
> 
> 
> psycopg2 sends the following to postgres (from the debug output):
> 
>  ...testsimple FROM stdin USING DELIMITERS ' ' WITH NULL AS '\N'
> 
> which postgres sort of interprets as N (eating the escape).  psycopg2
> should escape the string before sending it to postgres.
> 
> In some possible configurations, this could be a security hole.  If
> input from the user is passed to psycopg2 as the null parameter in the
> very reasonable assumption that psycopg2 should escape those values,
> something like null="'; <malicious code> where '' = '" would likely get

Yes, psycopg should quote that data. I'llfix this problem ASAP.

federico

--

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog@...
INIT.D Developer                                           fog@...
 If we are going to teach "creation science" as an alternative to
  evolution, then we should also teach the stork theory as an
  alternative to biological reproduction.                -- Judith Hayes
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
Nico Grubert | 22 Jul 11:03 2008
Picon

ProgrammingError - invalid byte sequence for encoding "UTF8"

Dear list members

I have 2 Zope servers (Zope 2.10.5, Python 2.4.4) on 2 physically 
separated machines. Both Zope servers access the same PostgreSQL (8.2.0) 
database on a remote server.

   Zope Server #1 has installed "psycopg2-2.0.5.1".
   Zope Server #2 has installed "psycopg2-2.0.6".

The Data.fs of both Zope Server #1 and #2 is the same.

On Zope Server #2, if I use a ZSQL Method to query the PostgreSQL 
database with umlauts (e.g. "lär") I get the following error:
On Zope Server #1 with installed "psycopg2-2.0.5.1" everything works fine.

Error Type: ProgrammingError
Error Value: invalid byte sequence for encoding "UTF8": 0xe47225 HINT: 
This error can also happen if the byte sequence does not match the 
encoding expected by the server, which is controlled by "client_encoding".

Traceback (innermost last):

     * Module ZPublisher.Publish, line 119, in publish
     * Module ZPublisher.mapply, line 88, in mapply
     * Module ZPublisher.Publish, line 42, in call_object
     * Module Shared.DC.ZRDB.DA, line 343, in manage_test
     * Module Shared.DC.ZRDB.DA, line 321, in manage_test
     * Module Shared.DC.ZRDB.DA, line 500, in __call__
       <SQL at /mysite/sql_searchMyDB>
     * Module Products.ZPsycopgDA.db, line 206, in query

If I query the PostgreSQL DB without umlauts, I get the results from the 
ZSQL method but on Zope Server #2 the umlauts are not displayed properly 
in the ZMI. On Server #1 the umlauts are correct.

I don't know if there is something wrong with my Zope or Python 
installation or if there is any difference between "psycopg2-2.0.5.1". 
and "psycopg2-2.0.6".

Any ideas?

Any tips are much appreciated.

Regards
Nico
James Henstridge | 22 Jul 11:49 2008
Picon

PATCH: cyclic GC traversal for psycopg types

Attached is a patch to add cyclic GC traversal support to the
extension types that Psycopg defines.  I have not implemented the
tp_clear method for any of the types so there can be cases where this
won't result in cycles being broken, but it should at least make them
visible to the GC (and related debugging tools).

If we find cases where objects get involved in unbreakable cycles, we
can look at adding tp_clear implementations (which probably also
involves more extensive checking of the reference handling in said
classes).

James.
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
Nico Grubert | 22 Jul 14:40 2008
Picon

Re: ProgrammingError - invalid byte sequence for encoding "UTF8"


> I have 2 Zope servers (Zope 2.10.5, Python 2.4.4) on 2 physically 
> separated machines. Both Zope servers access the same PostgreSQL (8.2.0) 
> database on a remote server.
> 
>   Zope Server #1 has installed "psycopg2-2.0.5.1".
>   Zope Server #2 has installed "psycopg2-2.0.6".

Note:
Downgrading Zope Server #2 to "psycopg2-2.0.5.1" solves all the problems.
James Henstridge | 22 Jul 15:08 2008
Picon

Re: ProgrammingError - invalid byte sequence for encoding "UTF8"

On Tue, Jul 22, 2008 at 8:40 PM, Nico Grubert <nicogrubert@...> wrote:
>
>> I have 2 Zope servers (Zope 2.10.5, Python 2.4.4) on 2 physically
>> separated machines. Both Zope servers access the same PostgreSQL (8.2.0)
>> database on a remote server.
>>
>>  Zope Server #1 has installed "psycopg2-2.0.5.1".
>>  Zope Server #2 has installed "psycopg2-2.0.6".
>
> Note:
> Downgrading Zope Server #2 to "psycopg2-2.0.5.1" solves all the problems.

How well do things work if you move forward to 2.0.7 or the development version?

James.

Gmane