title: HTTP Error 502.2 - Bad Gateway Configuring IIS 7 with Python 2.7
body: <p>I am a newbie to Stack Overflow (first post), but really see the use of this website.</p>
  
  <p>I'm stumped.  We are trying to setup IIS 7.0 to run with WinPython 2.7 on a Windows 7 machine.  </p>
  
  <p>I am an IIS newb, but veteran Python user.  IIS 7 can NOT find a library, which python finds, and executes, perfectly when ran on it's own.  When executed via IIS, the script fails with a traceback, and IIS returns the 502.2.  </p>
  
  <p>I found this thread <a href="http://forums.iis.net/p/1209465/2073173.aspx?HTTP+Error+502+2+Bad+Gateway+Frustrations" rel="nofollow">http://forums.iis.net/p/1209465/2073173.aspx?HTTP+Error+502+2+Bad+Gateway+Frustrations</a> but the advised solution is simply another troubleshooting suggestion.</p>
  
  <p>I found IIS's description (<a href="http://support.microsoft.com/kb/942057" rel="nofollow">http://support.microsoft.com/kb/942057</a>) of the error helpful, but futile.</p>
  
  <p>I found Python's start-up options/parameters helpful (<a href="http://docs.python.org/2/using/cmdline.html" rel="nofollow">http://docs.python.org/2/using/cmdline.html</a>), but futile.</p>
  
  <p>I found IIS's advice for configuring Python helpful (<a href="http://support.microsoft.com/kb/276494" rel="nofollow">http://support.microsoft.com/kb/276494</a>, but (questionably?) incomplete.</p>
  
  <p>This thread on manually defining an alternate bin folder (<a href="http://forums.asp.net/t/1303052.aspx?Tell+IIS+to+load+dll+from+another+directory+not+Bin+web+config+" rel="nofollow">http://forums.asp.net/t/1303052.aspx?Tell+IIS+to+load+dll+from+another+directory+not+Bin+web+config+</a>) might be where my solution lies, but I don't think it is because of the fact that this all worked on 2.6 without doing that to IIS.  </p>
  
  <p>IIS seems to allow python to import any module that is just a python script.  As soon as it gets to a *.pyd (basically just python's version of a dll file) file, it screams.  I'm no pro when it comes to DLLs and windows environments, but wouldn't IIS have to have paths to a bin folder of some kind? Do I have to manually edit them, as discussed in the last link above? </p>
  
  <p><strong>ACTUAL ERROR Details below for DLL failed Load:</strong></p>
  
  <p>The Error : </p>
  
  <blockquote>
    <p>" HTTP Error 502.2 - Bad Gateway The specified CGI application
    misbehaved by not returning a complete set of HTTP headers. The
    headers it did return are "Traceback (most recent call last): File
    "\estorage.equitable.int\riskmgmt\Quants\web\LinksPage.py", line 2,
    in  import pyweb File
    "\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pyweb__init__.py",
    line 5, in  from core import * File
    "\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pyweb\core.py",
    line 2, in  from pylib import pgdb File
    "\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pylib\pgdb.py",
    line 8, in  from scikits import timeseries as ts File
    "C:\WinPython-32bit-2.7.6.2-20140401\python-2.7.6\lib\site-packages\scikits.timeseries-0.91.3-py2.7-win32.egg\scikits\timeseries__init__.py",
    line 13, in  import const File
    "C:\WinPython-32bit-2.7.6.2-20140401\python-2.7.6\lib\site-packages\scikits.timeseries-0.91.3-py2.7-win32.egg\scikits\timeseries\const.py",
    line 79, in  from cseries import freq_constants ImportError:
    DLL load failed: The specified module could not be found. ".</p>
  </blockquote>
  
  <p>I'm confident that the python environment is configured properly, as the script runs from the same executable (python.exe) via a command line.  I'm thinking that I don't have IIS configured properly, for the new Python 2.7 install.  The same script worked yesterday, on IIS and python 2.6.  But during our upgrade from 2.6 to 2.7, a bunch of PATH and PYTHONPATH parameters all changed, plus we went from ActivePython to WinPython.  WinPython is "registered" on the machine.</p>
  
  <p>What I've tried</p>
  
  <ul>
  <li><p>confirming python's sys.path is as expected at run-time in both IIS and command line - it is.</p></li>
  <li><p>using the module from python command line.</p></li>
  <li><p>recompiling the failing module using two different compilers (ming32 and VS2008).</p></li>
  <li><p>putting duplicates of my new 2.7 modules in the old python26 folder.</p></li>
  <li><p>pulling out lots of hair and other hacky stuff.</p></li>
  </ul>
  
  <p>My next step, is to post this same message on a python forum.  If anybody can advise on a good one for python-IIS related challenges, that would be appreciated. </p>
  
  <p>Please help! Thanks in advance.</p>