FAQ
Hi!

Win7/x64, Python 3.2, PyPGSQL f 3.2 and Apahce 2.2.

I created a script that working in CGI mode, it is read some table,
and returns with an XML.

It was working with normal mode, under Pyscripter, and under command
line.

But!

When I trying to use it from Apache 2.2 as cgi, I got the subjected
error:

"No module named Pwd"

I checked the code.
Everything is fine for the lines
import postgresql # this is working
con = postgresql.open(....) # this failed

Traceback (most recent call last):
File "C:/web/Apache2.2/cgi-bin/testpg.py", line 20, in Session
Function()
File "C:/web/Apache2.2/cgi-bin/testpg.py", line 38, in WebFunction db
= postgresql.open("pq://postgres:m at localhost/webdbdb")
File "C:\python32\lib\site-packages\postgresql\__init__.py", line 76,
in open std_params = _pg_param.collect(prompt_title = None)
File "C:\python32\lib\site-packages\postgresql\clientparameters.py",
line 620, in collect cpd =
normalize(extrapolate(chain(*d_parameters)))
File "C:\python32\lib\site-packages\postgresql\clientparameters.py",
line 563, in normalize for (k, v) in iter:
File "C:\python32\lib\site-packages\postgresql\clientparameters.py",
line 524, in extrapolate for item in iter:
File "C:\python32\lib\site-packages\postgresql\clientparameters.py",
line 130, in defaults user = getuser() or 'postgres'
File "C:\python32\lib\getpass.py", line 156, in getuser import pwd
ImportError: No module named pwd

The Apache is running under my account (normal user).
The sys.path is ok:
['C:\\web\\Apache2.2\\cgi-bin', 'C:\\Windows\\system32\\python32.zip',
'C:\\python32\\DLLs', 'C:\\python32\\lib', 'C:\\python32', 'C:\
\python32\\lib\\site-packages']

So we (me, and the postgresql's author) don't understand, why it
happens.

Any idea?

Thanks for your help:
dd

Search Discussions

  • Peter Otten at Oct 21, 2011 at 9:33 am

    durumdara wrote:

    Hi!

    Win7/x64, Python 3.2, PyPGSQL f 3.2 and Apahce 2.2.

    I created a script that working in CGI mode, it is read some table,
    and returns with an XML.

    It was working with normal mode, under Pyscripter, and under command
    line.

    But!

    When I trying to use it from Apache 2.2 as cgi, I got the subjected
    error:

    "No module named Pwd"
    Remember that case matters in Python. Fortunately you included the
    traceback.
    I checked the code.
    Everything is fine for the lines
    import postgresql # this is working
    con = postgresql.open(....) # this failed

    Traceback (most recent call last):
    File "C:/web/Apache2.2/cgi-bin/testpg.py", line 20, in Session
    Function()
    File "C:/web/Apache2.2/cgi-bin/testpg.py", line 38, in WebFunction db
    = postgresql.open("pq://postgres:m at localhost/webdbdb")
    File "C:\python32\lib\site-packages\postgresql\__init__.py", line 76,
    in open std_params = _pg_param.collect(prompt_title = None)
    File "C:\python32\lib\site-packages\postgresql\clientparameters.py",
    line 620, in collect cpd =
    normalize(extrapolate(chain(*d_parameters)))
    File "C:\python32\lib\site-packages\postgresql\clientparameters.py",
    line 563, in normalize for (k, v) in iter:
    File "C:\python32\lib\site-packages\postgresql\clientparameters.py",
    line 524, in extrapolate for item in iter:
    File "C:\python32\lib\site-packages\postgresql\clientparameters.py",
    line 130, in defaults user = getuser() or 'postgres'
    File "C:\python32\lib\getpass.py", line 156, in getuser import pwd
    ImportError: No module named pwd
    The direct cause is that pwd is not available on Windows:

    http://docs.python.org/dev/py3k/library/pwd.html
    """
    33.2. pwd ? The password database
    Platforms: Unix
    This module provides access to the Unix user account and password database.
    It is available on all Unix versions.
    """

    The source of the failing function...

    '''
    def getuser():
    """Get the username from the environment or password database.

    First try various environment variables, then the password
    database. This works on Windows as long as USERNAME is set.

    """

    import os

    for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
    user = os.environ.get(name)
    if user:
    return user

    # If this fails, the exception will "explain" why
    import pwd
    return pwd.getpwuid(os.getuid())[0]
    '''

    ...suggests that you can make it work on Windows by setting the USERNAME
    environment variable (or any of the alternatives checked in the for-loop).

    Does postgresql use the os user as a fallback for the database user? If so
    you might consider providing the database user explicitly.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedOct 21, '11 at 8:51a
activeOct 21, '11 at 9:33a
posts2
users2
websitepython.org

2 users in discussion

Peter Otten: 1 post Durumdara: 1 post

People

Translate

site design / logo © 2022 Grokbase