Skip site navigation (1) Skip section navigation (2)

Re: psycopg used in a ASP page fails

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Jason Erickson <jerickso(at)stickpeople(dot)com>
Cc: Barend Köbben <kobben(at)itc(dot)nl>, "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: psycopg used in a ASP page fails
Date: 2011-02-17 09:46:12
Message-ID: (view raw, whole thread or download thread mbox)
Lists: psycopg
On Wed, Feb 16, 2011 at 8:37 PM, Jason Erickson
<jerickso(at)stickpeople(dot)com> wrote:

> Instead of 'import psycopg2', does the following code work when run as an
> ASP script?:
> ---------------------------------------------------------- from
> psycopg2._psycopg import __version__
> ----------------------------------------------------------
> For craziness sakes, does the following code work in ASP land?:
> ---------------------------------------------------------- from psycopg2
> import tz ----------------------------------------------------------
> Also, verify that the following file exist (which it should, since it works
> other ways):
>        %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2\
> Also, can you verify that there is not a psycopg directory or
> file in that same directory?
>        %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2
> You didn't mention what version of python you are using?
> With an ASP script, can you also try this code (I'm assuming that
> Response.Write is similar to print, change otherwise):
> ----------------------------------------------------------
> import sys Reponse.Write(sys.path)
> ----------------------------------------------------------
> This code will print the 'search' path for python modules.  This search path
> should be the same as when you run the python interpreter by hand, tho maybe
> ASP is adding something to it??  Verify that they are the same.
> Can you also verify that it is finding the correct 'module' with the
> following asp code:
> ----------------------------------------------------------
> import imp
> f, filename, description = imp.find_module('psycopg2')
> Response.Write('psycopg2 file location: '+filename)
> ----------------------------------------------------------
> What it prints should be the path to the psycopg2 install directory. Verify
> that it is pointing to the correct directory where you installed psycopg2,
> and that the file is in that directory.
> This is interesting because of where it fails.  First off, it is finding a
> psycopg2 directory, as it is importing (or trying to import) __init__.
> Second, it is not failing on loading the dll, but failing on a step before
> loading the dll, where it is loading a module inside the psycopg2 package
> (tz).  It is almost as if the sys.path is different between ASP land and
> normal land, causing the issue.
> It is possible that it is similar to the manifest issue that we see with
> modwsgi, but I'm thinking not.  Please try the beta version at:
> as well.


I've just found how to reproduce the the "cannot find tz". I think
it's still related to the failed dll import, but it happens _on the
second import_ of psycopg.

Artificially making the _psycopg import failing:

    $ sudo mv -vi /usr/lib/{,-}

The first import gives a clean error message:

    >>> import psycopg2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/piro/dev/psycopg2/dist/tmp/psycopg2/",
line 69, in <module>
        from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
    ImportError: cannot open shared object file: No such
file or directory

But the second gives:

    >>> import psycopg2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/piro/dev/psycopg2/dist/tmp/psycopg2/",
line 65, in <module>
        from psycopg2 import tz
    ImportError: cannot import name tz

So probably the first traceback is swallowed away somewhere.

The reason is in the order of the imports in psycopg2/
after the first import error what is imported in the system is:

    >>> print "\n".join(filter(re.compile("psyco").search,

it seems an inconsistent status with "" was loaded but
"psycopg2" is not available. Taking the care to have _psycopg imported
before the other submodules:

    ---	2011-02-16 23:02:27.000000000 +0000
    +++	2011-02-17 09:35:41.752056278 +0000
    @@ -62,8 +62,6 @@
     del sys, warnings

    -from psycopg2 import tz
     # Import the DBAPI-2.0 stuff into top-level module.

     from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
    @@ -78,6 +76,8 @@
     from psycopg2._psycopg import connect, apilevel, threadsafety, paramstyle
     from psycopg2._psycopg import __version__

    +from psycopg2 import tz
     # Register default adapters.

     import psycopg2.extensions as _ext

we can get the consistent import error about the failed _psycopg import.

Barend, if you could change the psycopg2/ as shown above
and repeat your test we may get the real reason of the failed import.
Please don't forget to include the Python and psycopg versions you are
using, and to make a test with the 2.4 beta2 too. Thank you.

-- Daniele

In response to


psycopg by date

Next:From: Barend KöbbenDate: 2011-02-17 10:05:52
Subject: Re: psycopg used in a ASP page fails
Previous:From: Jason EricksonDate: 2011-02-16 21:00:46
Subject: Re: RELEASE: psycopg 2.4 beta 2

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group