Serving Bazaar with Apache on Windows XP

Asked by yamamura seiya

Can't get smart server to work on Windows with the instructions given at
http://doc.bazaar.canonical.com/bzr.2.2/en/user-guide/http_smart_server.html
(use mod_wsgi)

I can execute "log", "branch", "checkout" command, but "commit" command fails with the following error

bzr: ERROR: Server sent an unexpected error: ('error', 'No module named pwd')

Configuration Apache httpd.conf:
 WSGIScriptAliasMatch ^/bzr/.*/\.bzr/smart$ C:/bazaar_test/server/scripts/bzr.wsgi
 WSGIRestrictStdout Off
 RewriteEngine On
 RewriteCond %{REQUEST_URI} !^/bzr/.*/\.bzr/smart$
 RewriteRule ^/bzr/(.*/\.bzr/.*)$ C:/bazaar_test/server/rep_bzr/$1 [L]
 <Directory C:/bazaar_test/server/rep_bzr>
     WSGIApplicationGroup %{GLOBAL}
 </Directory>

Apache smart server wsgi script bzr.wsgi:
 import sys
 sys.path.insert(0, "C:/Bazaar/lib/library.zip")

 from bzrlib.transport.http import wsgi

 def application(environ, start_response):
     app = wsgi.make_app(
         root="C:/bazaar_test/server/rep_bzr/",
         prefix="/bzr/",
         path_var='REQUEST_URI',
         readonly=False,
         load_plugins=True,
         enable_logging=True)
     return app(environ, start_response)

execute following command

 >bzr log bzr+http://localhost/bzr/trunk <-- OK
 >bzr checkout bzr+http://localhost/bzr/trunk <-- OK

 >bzr commit -m "test"
 bzr: ERROR: Server sent an unexpected error: ('error', 'No module named pwd')

Question information

Language:
English Edit question
Status:
Answered
For:
Bazaar Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
John A Meinel (jameinel) said :
#1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8/31/2010 2:47 AM, yamamura seiya wrote:
> New question #123463 on Bazaar:
> https://answers.launchpad.net/bzr/+question/123463
>
> Can't get smart server to work on Windows with the instructions given at
> http://doc.bazaar.canonical.com/bzr.2.2/en/user-guide/http_smart_server.html
> (use mod_wsgi)
>
> I can execute "log", "branch", "checkout" command, but "commit" command fails with the following error
>
> bzr: ERROR: Server sent an unexpected error: ('error', 'No module named pwd')
>
> Configuration Apache httpd.conf:
> WSGIScriptAliasMatch ^/bzr/.*/\.bzr/smart$ C:/bazaar_test/server/scripts/bzr.wsgi
> WSGIRestrictStdout Off
> RewriteEngine On
> RewriteCond %{REQUEST_URI} !^/bzr/.*/\.bzr/smart$
> RewriteRule ^/bzr/(.*/\.bzr/.*)$ C:/bazaar_test/server/rep_bzr/$1 [L]
> <Directory C:/bazaar_test/server/rep_bzr>
> WSGIApplicationGroup %{GLOBAL}
> </Directory>

^- Is there a .bzr.log file you can get access to (something controlled
by the apache service, the default is to go into Documents/.bzr.log).

'pwd' is a Unix module to look up a user's information. We are trying to
figure out who to commit as.

Newer versions of bzr will require you to run "bzr whoami" first, rather
than guessing (because it was very hard to guess accurately). So you
probably can run that directly and avoid the lookup.

However, I would be very curious to know what python, etc you are
running. The code in question should be "bzrlib/config.py" _auto_user_id()

And looking at it, it does a platform check first:

    if sys.platform == 'win32':
        name = win32utils.get_user_name_unicode()
...
 return name, (name + '@' + host)

    try:
        import pwd
        ...
    except ImportError:
        import getpass
        ...

However, looking at it:

1) If you are on Windows, it shouldn't be trying the 'import pwd' code
at all.

2) If it *did* fail to import pwd, then it should be falling back to
'import getpass' (which *does* exist on windows).

Can you give more details about version of python, version of bzr, etc?

Thanks,
John
=:->

PS> Again, the short fix is to probably just run 'bzr whoami', but if
you want to help us figure out what is going on we could use more detail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkx9BjUACgkQJdeBCYSNAANgXwCeKi/n6mV5x0tKVJqd3lfV/796
HGIAn2WELG8CFV9tIIcSWh+aQ8gVaq0e
=D0YK
-----END PGP SIGNATURE-----

Revision history for this message
yamamura seiya (yamamura-seiya) said :
#2

Thanks for the answer.

But run 'bzr whoami' and try again, the same error occurs

software version is as follows.

python: 2.6.6
apache: 2.2.16
mod_wsgi: mod_wsgi-win32-ap22py26-3.3.so
bazaar: 2.2.0 (use standalone installer)

This time, I tried to access a remote server from a client,
(Both versions of 'Bazaar' are the same, and run 'bzr whoami' )
But "commit" command fails with same error

Nothing output in '.bzr.log' and apache's 'error.log' of server side.
Client side '.bzr.log' as follws.
---
Wed 2010-09-01 13:02:30 +0900
0.125 bazaar version: 2.2.0
0.125 bzr arguments: [u'whoami', u'Lin <email address hidden>']
0.125 looking for plugins in C:/Documents and Settings/Administrator/Application Data/bazaar/2.0/plugins
0.125 looking for plugins in C:/Program Files/Bazaar/plugins
0.265 encoding stdout as sys.stdout encoding 'cp932'
0.265 Transferred: 0kB (0.0kB/s r:0kB w:0kB)
0.265 return code 0

Wed 2010-09-01 13:02:41 +0900
0.125 bazaar version: 2.2.0
0.125 bzr arguments: [u'whoami']
0.125 looking for plugins in C:/Documents and Settings/Administrator/Application Data/bazaar/2.0/plugins
0.125 looking for plugins in C:/Program Files/Bazaar/plugins
0.265 encoding stdout as sys.stdout encoding 'cp932'
0.312 Transferred: 0kB (0.0kB/s r:0kB w:0kB)
0.312 return code 0

Wed 2010-09-01 13:02:59 +0900
0.109 bazaar version: 2.2.0
0.109 bzr arguments: [u'commit', u'-m', u'commit test']
0.125 looking for plugins in C:/Documents and Settings/Administrator/Application Data/bazaar/2.0/plugins
0.125 looking for plugins in C:/Program Files/Bazaar/plugins
0.265 encoding stdout as sys.stdout encoding 'cp932'
0.312 opening working tree 'C:/bzr_test/localpj1/trunk'
0.375 bzr-svn: using Subversion 1.6.6 ()
2.625 preparing to commit
4.703 Traceback (most recent call last):
  File "bzrlib\commands.pyo", line 911, in exception_to_return_code
  .
  .
UnknownErrorFromSmartServer: Server sent an unexpected error: ('error', 'No module named pwd')

4.703 Transferred: 13kB (3.1kB/s r:6kB w:7kB)
4.703 return code 3
[ 1328] 2010-09-01 13:11:03.996 INFO: Discarding watch for C:\bzr_test\localpj1\trunk - it has expired
--

Revision history for this message
Marius Kruger (amanica) said :
#3

Are you sure that you looked in the right place for the server side .bzr.log ?
I think it will be in the windows equivalent of the home directory of the user that runs apache.
I would expect the real cause would be there.

Revision history for this message
yamamura seiya (yamamura-seiya) said :
#4

Sorry, I run apache as Windows Service (user: SYSTEM) , but I check my account's '.bzr.log'

And run apache as my Windows account, I succeeded in 'commit'.

Probably this error occurs only when run apache as 'SYSTEM' user
I found '.bzr.logr' when run apache as 'SYSTEM' user . as follws
---
Wed 2010-09-01 19:55:33 +0900
4.243 Traceback (most recent call last):
  File "bzrlib\smart\request.pyo", line 355, in _call_converting_errors
  File "bzrlib\smart\request.pyo", line 140, in execute
  File "bzrlib\smart\branch.pyo", line 52, in do
  File "bzrlib\smart\branch.pyo", line 319, in do_with_branch
  File "bzrlib\branch.pyo", line 2457, in lock_write
  File "bzrlib\lockable_files.pyo", line 187, in lock_write
  File "bzrlib\lockdir.pyo", line 606, in lock_write
  File "bzrlib\lockdir.pyo", line 521, in wait_lock
  File "bzrlib\lockdir.pyo", line 482, in attempt_lock
  File "bzrlib\lockdir.pyo", line 224, in _attempt_lock
  File "bzrlib\lockdir.pyo", line 290, in _create_pending_dir
  File "bzrlib\lockdir.pyo", line 452, in _prepare_info
  File "bzrlib\osutils.pyo", line 2329, in getuser_unicode
  File "getpass.pyo", line 152, in getuser
ImportError: No module named pwd

Revision history for this message
John A Meinel (jameinel) said :
#5

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 9/1/2010 6:08 AM, yamamura seiya wrote:
> Question #123463 on Bazaar changed:
> https://answers.launchpad.net/bzr/+question/123463
>
> Status: Needs information => Open
>
> yamamura seiya gave more information on the question:
> Sorry, I run apache as Windows Service (user: SYSTEM) , but I check my
> account's '.bzr.log'
>
> And run apache as my Windows account, I succeeded in 'commit'.
>
> Probably this error occurs only when run apache as 'SYSTEM' user
> I found '.bzr.logr' when run apache as 'SYSTEM' user . as follws
> ---
> Wed 2010-09-01 19:55:33 +0900
> 4.243 Traceback (most recent call last):
> File "bzrlib\smart\request.pyo", line 355, in _call_converting_errors
> File "bzrlib\smart\request.pyo", line 140, in execute
> File "bzrlib\smart\branch.pyo", line 52, in do
> File "bzrlib\smart\branch.pyo", line 319, in do_with_branch
> File "bzrlib\branch.pyo", line 2457, in lock_write
> File "bzrlib\lockable_files.pyo", line 187, in lock_write
> File "bzrlib\lockdir.pyo", line 606, in lock_write
> File "bzrlib\lockdir.pyo", line 521, in wait_lock
> File "bzrlib\lockdir.pyo", line 482, in attempt_lock
> File "bzrlib\lockdir.pyo", line 224, in _attempt_lock
> File "bzrlib\lockdir.pyo", line 290, in _create_pending_dir
> File "bzrlib\lockdir.pyo", line 452, in _prepare_info
> File "bzrlib\osutils.pyo", line 2329, in getuser_unicode
> File "getpass.pyo", line 152, in getuser
> ImportError: No module named pwd
>

So 'pwd' doesn't exist on Windows, and it seems the other variables
aren't set. Specifically it is trying to do:

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]

On my Windows system, both "USER" and "USERNAME" are set. Maybe you
could set them for the SYSTEM user? (it would seem that in lock files,
we don't use 'whoami' information, but only the system identifier...)

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkx+TVcACgkQJdeBCYSNAAMt2ACfXpwXdRiN/L8pEM1V6rFA8Fn2
vyYAoNI5VE5SMvmL2uMMRw4i9ymxnYQo
=BVbe
-----END PGP SIGNATURE-----

Revision history for this message
nataly nanda huanca patzi (nhuanca) said :
#6

Sorry, I want to know What configure I make for obtain bzr.log as this.
Wed 2010-09-01 19:55:33 +0900
4.243 Traceback (most recent call last):
  File "bzrlib\smart\request.pyo", line 355, in _call_converting_errors
  File "bzrlib\smart\request.pyo", line 140, in execute
  File "bzrlib\smart\branch.pyo", line 52, in do
  File "bzrlib\smart\branch.pyo", line 319, in do_with_branch
  File "bzrlib\branch.pyo", line 2457, in lock_write
  File "bzrlib\lockable_files.pyo", line 187, in lock_write
  File "bzrlib\lockdir.pyo", line 606, in lock_write
  File "bzrlib\lockdir.pyo", line 521, in wait_lock
  File "bzrlib\lockdir.pyo", line 482, in attempt_lock
  File "bzrlib\lockdir.pyo", line 224, in _attempt_lock
  File "bzrlib\lockdir.pyo", line 290, in _create_pending_dir
  File "bzrlib\lockdir.pyo", line 452, in _prepare_info
  File "bzrlib\osutils.pyo", line 2329, in getuser_unicode
  File "getpass.pyo", line 152, in getuser
ImportError: No module named pwd

Revision history for this message
Jelmer Vernooij (jelmer) said :
#7

On 11/03/2011 07:55 PM, nataly nanda huanca patzi wrote:
> Question #123463 on Bazaar changed:
> https://answers.launchpad.net/bzr/+question/123463
>
> nataly nanda huanca patzi posted a new comment:
> Sorry, I want to know What configure I make for obtain bzr.log as this.
> Wed 2010-09-01 19:55:33 +0900
> 4.243 Traceback (most recent call last):
> File "bzrlib\smart\request.pyo", line 355, in _call_converting_errors
> File "bzrlib\smart\request.pyo", line 140, in execute
> File "bzrlib\smart\branch.pyo", line 52, in do
> File "bzrlib\smart\branch.pyo", line 319, in do_with_branch
> File "bzrlib\branch.pyo", line 2457, in lock_write
> File "bzrlib\lockable_files.pyo", line 187, in lock_write
> File "bzrlib\lockdir.pyo", line 606, in lock_write
> File "bzrlib\lockdir.pyo", line 521, in wait_lock
> File "bzrlib\lockdir.pyo", line 482, in attempt_lock
> File "bzrlib\lockdir.pyo", line 224, in _attempt_lock
> File "bzrlib\lockdir.pyo", line 290, in _create_pending_dir
> File "bzrlib\lockdir.pyo", line 452, in _prepare_info
> File "bzrlib\osutils.pyo", line 2329, in getuser_unicode
> File "getpass.pyo", line 152, in getuser
> ImportError: No module named pwd
>
This seems like an issue in the getpass module - it shouldn't be trying
to use the pwd module on Windows.

How did you install bzr, using the standalone windows installer? Or did
you install it for an existing python installation?

Cheers,

Jelmer

Revision history for this message
John A Meinel (jameinel) said :
#8

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/03/2011 08:15 PM, Jelmer Vernooij wrote:
> Question #123463 on Bazaar changed:
> https://answers.launchpad.net/bzr/+question/123463
>
> Jelmer Vernooij proposed the following answer: On 11/03/2011 07:55
> PM, nataly nanda huanca patzi wrote:
>> Question #123463 on Bazaar changed:
>> https://answers.launchpad.net/bzr/+question/123463
>>
>> nataly nanda huanca patzi posted a new comment:

I didn't follow this from the beginning. But there is a bug on Windows
that if $USER isn't set, it ends up falling back to modules that
aren't available trying to find the username.

Generally this happens when bzr is installed as a service (eg not run
directly from a user). And setting USER as an environment variable for
the system user fixes this.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6y6V4ACgkQJdeBCYSNAAPUpwCffko8lFQcE/GUMmoqLDzzVpNo
lnAAn0zS7j4J2raiCdZrDS1heh7Tzois
=HfZf
-----END PGP SIGNATURE-----

Revision history for this message
Vincent Ladeuil (vila) said :
#9

Trying to access 'pwd' on windows when USER is not set and bzr try to access .bzr.log sounds like a known (and fixed in recent versions) bug.

Setting BZR_LOG should work around the problem until you upgrade.

Can you help with this problem?

Provide an answer of your own, or ask yamamura seiya for more information if necessary.

To post a message you must log in.