16

I'm trying to set up Mercurial repositories to be hosted by IIS under Windows Server 2003. Following this post I installed Python 2.5.4.4 and Mercurial 1.3, set up virtual dir, extracted library.zip and created hgwebdir.config.

However, when I trying to open the http://hostname/hg/hgwebdir.cgi I got an error “The specified CGI application misbehaved by not returning a complete set of HTTP headers.” I did all by best:

  1. Checked IIS mappings to both .py and .cgi extensions. I even tried to use FastCGI with no success.
  2. Created “Hello World” in the same dir and checked that it works fine.
  3. Checked read/exec permissions to Python, IIS and repos directories for IUSR, IWAM and NETWORK SERVICE.
  4. Tried to apply two different patches from Mercurial mailing list. Since they both are old I haven't success with it.
  5. INstalled Sysinternals' procmon and checked for filesystem errors during request. I found nothing except lots of Buffer Overflow results in Python process while it loads it's libraries.
  6. Tried to add 'Content-type: text/html' to the script.

One more thing is when I'm requesting inexistent script file (e.g /hg/inexist.cgi) I have the same error. Nothing helped!

Community
  • 1
  • 1
Artem Koshelev
  • 10,548
  • 4
  • 36
  • 68

5 Answers5

6

Some more things that I needed to fix:

  • Where the various HOWTOs say to use c:\whatever\Python26\python.exe -u "%s" "%s" instead use c:\whatever\Python26\python.exe -u -O -B "%s" "%s" -O causes it to also look for .pyo files (not just .py or .pyc, which at least in my version weren't present). -B causes it to not attempt to compile .py files that it finds into .pyo files (which fails due to lacking write permissions)
  • I'd installed Python 2.7. Mercurial 1.6.2's .pyo files were compiled with Python 2.6. This resulted in a magic number error. Uninstalling 2.7 and installing 2.6.5 fixed this. (If you're reading this at some point in the future, this point may no longer be relevant - check the name of the DLL in Mercurial's directory, or TortoiseHg's directory, depending on where you took library.zip from)
  • hgwebdir.cgi is now just hgweb.cgi - webdir was integrated into it
Jon Bright
  • 13,388
  • 3
  • 31
  • 46
2

In my situation, this error caused by line application = hgwebdir('c:\somewhere\hgweb.config') in hgweb.cgi, it should be application = hgweb('c:\somewhere\hgweb.config').

Besides, uncomment line import cgitb; cgitb.enable() in hgweb.cgi will give you more info about the error( and other errors).

P.S. I use Python 2.6.6 and Mercurial 1.7.3 on Windows Server 2003 with IIS 6.0.

jjooeell
  • 113
  • 1
  • 7
2

In my case, the critical step that fixed it was using:

c:\whatever\Python26\python.exe -u -O -B "%s" "%s

Before that it was not working with the error:

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

 c:\hg\hgweb.cgi in ()
   13 import cgitb; cgitb.enable()
   14 
   15 from mercurial import demandimport; demandimport.enable()
   16 from mercurial.hgweb import hgweb, wsgicgi
   17 application = hgweb(config)
mercurial undefined, demandimport undefined
<type 'exceptions.ImportError'>: No module named mercurial 
      args = ('No module named mercurial',) 
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
BrotherOdin
  • 132
  • 8
1

Finally I got that "no headers" error returned on any python script error, so I checked script with console interpreter and fixed errors in my config file. And of course I should ask this question at ServerFault instead of StackOverflow - the lack of sleep did the job :)

Artem Koshelev
  • 10,548
  • 4
  • 36
  • 68
  • Hey there - so what was the actual problem with the cgi in the end? I'm still suffering with this one.. – Mr AH May 14 '10 at 09:11
  • I'm encountering a similar issue. Could you post what you had to change in order to fix your problem? – Peter Bernier Jun 03 '10 at 19:12
  • In my case there was an error in config file. Launch the script on the local computer “python index.py” and inspect the output. – Artem Koshelev Jun 14 '10 at 16:40
1

There's a pretty good post at http://vampirebasic.blogspot.com/2009/06/running-mercurial-on-windows.html that'll get you started, but if you need more detail or to go further than the writer did, I've got a 4 part blog post that covers everything you need to know about getting up and running on IIS, including Active Directory integration, pull/push privileges, customization of the UI:

http://www.endswithsaurus.com/2010/05/setting-up-and-configuring-mercurial-in.html

It's worth a read...

BenAlabaster
  • 39,070
  • 21
  • 110
  • 151