wfastcgi , iis & python 3 not working?

1,530 views
Skip to first unread message

martel berends

unread,
Oct 22, 2019, 2:25:34 AM10/22/19
to web2py-users
I'm trying to deploy a web2py server with the following specs:
- Windows server 2019
- IIS 10
- Python 3.5 above

I followed the deployment scripts in de manual (http://web2py.com/books/default/chapter/29/13/deployment-recipes#IIS) and the excellent video of Remco Boerma (https://youtu.be/gxOhsThD0FY

I've the basic site working, but when I go to the admin section, an error occurs :

Error occurred:

Traceback (most recent call last):
  File "c:\python36-32\lib\site-packages\wfastcgi.py", line 851, in main
    response.send(FCGI_STDOUT, part)
  File "c:\python36-32\lib\site-packages\wfastcgi.py", line 756, in send
    return send_response(self.stream, self.record.req_id, resp_type, content, streaming)
  File "c:\python36-32\lib\site-packages\wfastcgi.py", line 370, in send_response
    raise TypeError("content must be encoded before sending: %r" % content)
TypeError: content must be encoded before sending: 'a'

I've tried python 3.4 / 3.5 / 3.6 and 3.7 but all with the same result. Going back to 2.7 is not what I want, due to end-of-life of python 2.7 and my site is coded in Python 3. 
I've installed the source-code version of web2py and the user-registration in the standard welcome application is working fine. So the patform seems to work. 

It's something between web2py and wfastcgi, but I've no clue what is causing this error and how to solve it. 

Any help would be fantastic. 

Davidiam

unread,
Oct 22, 2019, 8:42:28 AM10/22/19
to web...@googlegroups.com
We have more or less the same configuration with no issues.
Here are some notes from our install :
  • routes.py : set path prefix to match the name of the virtual server we created for web2py apps

routers = dict(BASE=dict(path_prefix = "XXX"))

  • in web.config modify the fastcgi line as shown here :

 <add name="Python_via_FastCGI" path="handler.web2py" verb="*" modules="FastCgiModule" scriptProcessor="<path 2 python installation>\python.exe|<path to web2py install>\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />

  • Install fastcgi handler in IIS at server level for web2py installation
  • In IIS, create a new application pool with the name for web2py
  • In application pool --> Advanced settings : make sure the application pool runs with the correct account

One thing that might help you though 
You can setup the admin app to work over https:

https://www.youtube.com/watch?v=_4to_44DcJU  time :   46:15

Run from web2py base folder :

For 2.7 :

from gluon.main import save_password; save_password(raw_input('admin password: '),443)

For 3.x

from gluon.main import save_password; save_password(input('admin password: '),443)


but otherwise you should be able to run the admin via http from the server.

Good luck,
David

Константин Комков

unread,
Oct 22, 2019, 9:11:49 AM10/22/19
to web2py-users
I have Windows Server 2019, IIS 10, Python 3.7.3, web2py 2.18.5 and it's work.
You need to try that web.config:
<?xml version="1.0" encoding="UTF-8"?>
<!-- app configuration for web2py on IIS -->
<configuration>
 
<appSettings>
   
<add key="WSGI_HANDLER" value="gluon.main.wsgibase" />
   
<add key="WSGI_RESTART_FILE_REGEX" value=".*((routes\.py)|(\.config))$" />
 
</appSettings>
 
<system.webServer>
   
<rewrite>
     
<rules>
       
<clear />
       
<rule name="static" enabled="true" stopProcessing="true">
         
<match url="^(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$" />
         
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
         
<action type="Rewrite" url="applications/{R:1}/static/{R:2}" logRewrittenUrl="false" />
       
</rule>
       
<rule name="web2py_app" enabled="true" stopProcessing="true">
         
<match url="(.*)" ignoreCase="false" />
         
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
         
<action type="Rewrite" url="handler.web2py/{R:1}" appendQueryString="true" />
       
</rule>
     
</rules>
     
<outboundRules>
       
<rule name="static_version_cache_control" preCondition="static_version">
         
<match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
         
<action type="Rewrite" value="max-age=315360000" />
         
<conditions>
         
</conditions>
       
</rule>
       
<rule name="static_version_Expires" preCondition="static_version">
         
<match serverVariable="RESPONSE_Expires" pattern=".*" />
         
<action type="Rewrite" value="Thu, 31 Dec 2037 23:59:59 GMT" />
       
</rule>
       
<preConditions>
         
<preCondition name="static_version">
           
<add input="{REQUEST_URI}" pattern="(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$" />
         
</preCondition>
       
</preConditions>
     
</outboundRules>
   
</rewrite>
 
</system.webServer>
</configuration>

martel berends

unread,
Oct 23, 2019, 2:12:43 AM10/23/19
to web2py-users
Hi all

Thanks a lot, the  step-by-step guide helped. Everything was already done, only one thing was missing. The error was caused by the missing parameter file that's generated by the code : from gluon.main import save_password; save_password(input('admin password: '),443) 

The web.config is exactly the same as the one in the example directory, but is missing the <handlers> section. I figured out that this als can be configured in the IIS-manager. This helped to get insight in the relation between IIS & Python.

Regards,

Martel


Op dinsdag 22 oktober 2019 08:25:34 UTC+2 schreef martel berends:
Reply all
Reply to author
Forward
0 new messages