1

My flask app is in D:\Applications\AccidentIdClassifier\flask_app.py and contains a flask app called app. I can run it fine on my local system.

I set up a Conda environment that I'd like to use for this app. I'm not sure how to get the web.config file to reference the necessary conda environment. I started out just setting the WSGI_HANDLER to flask_app.app but I got an error about not being able to import a numpy dll which I believe is related to the venv not be activated.

I saw some discussion about using ptvs_virtualenv_proxy.handler for the WSGI_HANDLER value and to then use WSGI_ALT_VIRTUALENV_HANDLER and WSGI_ALT_VIRTUALENV_ACTIVATE_THIS but I don't know where to get a activate_this.py and I'm not sure if I need to do anything to prime the pumps for ptvs_virtualenv_proxy.handler

Here's theweb.config that I currently have (that isn't working)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
  <handlers>
   <remove name="Python27_via_FastCGI" />
   <remove name="Python34_via_FastCGI" />
   <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" 
        scriptProcessor="C:\ProgramData\Anaconda3\python.exe|C:\ProgramData\Anaconda3\Lib\site-packages\wfastcgi.py" 
        resourceType="Unspecified" requireAccess="Script" />
  </handlers>
</system.webServer>
<appSettings>
  <!-- Required settings -->
  <add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.handler" />
  <add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="c:\inetpub\pyroot\default\env\Scripts\activate_this.py" />
  <add key="WSGI_ALT_VIRTUALENV_HANDLER" value="flask_app.app" /> 
  <add key="PYTHONPATH" value="D:\Applications\AccidentIdClassifier" />
</appSettings>
    <system.web>
        <identity impersonate="false" />
    </system.web>
</configuration>
RagingRoosevelt
  • 2,046
  • 19
  • 34
  • Have you checked whether wfastcgi has been configured correctly? IIS just works as a proxy, you only have to create handler and environment variables. Then when you activate the application, wfastcgi should read environment configuration from web.config. Then you should be able to get them from .getenv.In addition have you run wfastcgi-enable before? – Jokies Ding Mar 11 '20 at 09:20
  • @JokiesDing, I believe so. I `pip install`'ed wfastcgi and ran `wfastcgi-enable`. It returned a message saying that the `python.exe` and `wfastcgi.py` that I specified were set up as a FastCGI scrip processor. – RagingRoosevelt Mar 11 '20 at 16:12

1 Answers1

1

I ended up stumbling on this question and answer. I tried creating a new conda virtual environment using Python 3.6.5 and then adjusting my web.config to the new python.exe and wfastcgi.py locations and was still getting various errors. Experimentally, I dropped the venv properties and ended up with just

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
  <handlers>
   <remove name="Python27_via_FastCGI" />
   <remove name="Python34_via_FastCGI" />
   <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule"
        scriptProcessor="C:\ProgramData\Anaconda3\envs\AccidentId\python.exe|C:\ProgramData\Anaconda3\envs\AccidentId\Lib\site-packages\wfastcgi.py" 
        resourceType="Unspecified" requireAccess="Script" />
  </handlers>
</system.webServer>
<appSettings>
  <!-- Required settings -->
  <add key="PYTHONPATH" value="D:\Applications\AccidentIdClassifier" />
  <add key="WSGI_HANDLER" value="flask_app.app" /> 
</appSettings>
    <system.web>
        <identity impersonate="false" />
    </system.web>
</configuration>

which seems to work fine.

The only conclusion I can draw is that IIS was struggling with something about python 3.7 and that 3.6.5 got it working. Anaconda doesn't seem to mind connecting directly to the python binary without worrying more about virtual environments, so that seems to make the effort in that direction redundant.

RagingRoosevelt
  • 2,046
  • 19
  • 34