Help! import winrandom gives dll load failed error under Apache on Vista, but works under Rocket.

631 views
Skip to first unread message

dlypka

unread,
Oct 6, 2011, 10:19:41 PM10/6/11
to web2py-users
My web2py app which uses paramiko sftp, works fine under the Rocket
webserver,
but fails here when run under the Apache 2.2 webserver, under WINDOWS
VISTA Enterprise:

• File "C:\Python27\lib\site-packages\Crypto\Random\OSRNG\nt.py", line
28

import winrandom <------ failing to load some DLL at line 28
----------
from rng_base import BaseRNG

I imagine it is some kind of permissions problem, maybe with having to
load a cryptographic C dll

I have already run a Process viewer and cleaned up the PATH to avoid
dll search failures.

This is a proof of concept app to a major U.S. corporation. They have
already seen it work under Rocket
and are very excited to see it deployed under a standard webserver.

An alternative is to use IIS7 but the web2py slice I read looked very
difficult to follow so I am trying Apache first.
We are also running Symantec anti virus (corporate edition) and we are
locked out from being able to disable it.
Not sure if antivirus interferes with Apache. We only have this
corporate PC to use at the moment.

I would appreciate any clues or tips for configuring Apache to load
paramiko sftp under Windows.
Or links to straight-forward and $free steps for installing web2py
under IIS 7 in Vista.









dlypka

unread,
Oct 10, 2011, 7:36:34 PM10/10/11
to web2py-users
Resolved:

After researching, I see this problem plagues many other developers as
well.
The root cause is that the Distribution Windows Build of Apache 2.2 is
built with msvcr71.dll which is the C++ runtime dll
for Visual Studio 2003!!! But, most recent builds of python .pyd files
which link to C/C++ code, are built with msvcr90.dll which is the one
from Visual Studio 2008. As a result, Apache chokes with this obscure
error (failure to load a dll) whenever a pyd is imported that is built
with any C/C+ runtime which is not msvrcr71.dll. If you run httpd.exe
from a command prompt, you will get an error popup for Microsoft error
R6034.

In particular, if you want to used sftp in python on Apache 2.2, you
cannot do so using the distributed Windows build of Apache 2.2.
However, there are lots of postings showing how to build Apache 2.2
yourself under Visual Studio 2008, so that would be the workaround for
running web2py on a Windows platform under Apache 2.2 when you are
doing sftp or something using C/C++ code. See
http://comments.gmane.org/gmane.comp.apache.devel/43600 where it
mentions that Apache 2.4 will finally
be built with a current Microsoft C++ runtime dll.
Another workaround if you do not want to build Apache in VS 2008, is
to try to run web2py under IIS.
I got it working under IIS 7 on Vista, but yes, it is quite difficult
to do even with the easiest of the 3 methods
described in the web2py slice about IIS. The easiest method is to use
Rocket together with IIS 7, where IIS 7 is used as a proxy for
Rocket. Additional steps to take regarding what is mentioned in the
slice is to create web application in IIS 7 to serve as a kind of
surrogate for the web2py application. Plus the specifics of the
routes.py entries and of the .NET URL rewriter file
ManagedFusion.Rewriter.txt are pretty much have to discovered by
experimentation.
Here is what works for my web2py app named 'UETR' on IIS 7:

ManagedFusion.Rewriter.txt
-------------------------------------------------------
RewriteEngine On
RewriteBase /
RewriteRule ^(/) http://138.85.50.99:8000/UETR?r=$1 [R,NC]

c:\web2py\routes.py
-----------------------

default_application = 'UETR' # ordinarily set in base routes.py
default_controller = 'default' # ordinarily set in app-specific
routes.py
default_function = 'index' # ordinarily set in app-specific
routes.py

routes_app = ((r'/(?P<app>welcome|admin|uetr)\b.*', r'\g<app>'),
(r'(.*)', r'UETR'),
(r'/?(.*)', r'UETR'))

routes_in = ((r'.*:/favicon.ico', r'/examples/static/favicon.ico'),
(r'.*:/robots.txt', r'/examples/static/robots.txt'),
(r'.*:/LTE1/index', r':8000/UETR/default/
index'),
((r'.*http:/localhost.* (?P<any>.*)', r'http://localhost:
8000/UETR/default/index')))

routes_out = ((r'.*http://otherdomain.com.* /app/ctr(?P<any>.*)',
r'\g<any>'),
(r'/app(?P<any>.*)', r'\g<any>'))
----------------------------------------------------------------------------------------------
I created an ASP.NET 4.0 web application on IIS 7 whose Virtual
Directory name is 'LTE1'
In it, I used the Visual Studio 2010 wizard to create a basic web
application (hello world roughly).
In that web application I had to modify the web.config as per the
documentation for ManagedFusion.Rewriter
I also created a 'bin' folder in LTE1 and copied the Managed Fusion
dll into into it.

The actual content of the .aspx pages in this .NET web app are
irrelevant as this app is never
rendered. Only its web.config is read and acted upon by Managed
Fusion, to cause the request to be passed to
the URL where web2py is running on Rocket at port 8000.
---------------------------------------------------------------------------------------------
Now if I browse to
http://138.85.50.99/LTE1

It hits IIS 7 and magically reroutes to my UETR web2py app at
http://138.85.50.99:8000/UETR?r=/LTE1

More work is needed to refine it, but the basic functionality is
shown.

dlypka

unread,
Oct 12, 2011, 2:52:34 AM10/12/11
to web2py-users
P.S.
In this scenario, you have to run web2py with
-i 138.85.50.99 -p 8000
for example:
python web2py.py -a "<recycle>" -i 138.85.50.99 -p 8000

On Oct 10, 6:36 pm, dlypka <dly...@gmail.com> wrote:
> Resolved:
>
> After researching, I see this problem plagues many other developers as
> well.
> The root cause is that the Distribution Windows Build of Apache 2.2 is
> built with msvcr71.dll which is the C++ runtime dll
> for Visual Studio 2003!!! But, most recent builds of python .pyd files
> which link to C/C++ code, are built with msvcr90.dll which is the one
> from Visual Studio 2008.  As a result, Apache chokes with this obscure
> error (failure to load a dll) whenever a pyd is imported that is built
> with any C/C+ runtime which is not msvrcr71.dll.  If you run httpd.exe
> from a command prompt, you will get an error popup for Microsoft error
> R6034.
>
> In particular, if you want to used sftp in python on Apache 2.2, you
> cannot do so using the distributed Windows build of Apache 2.2.
> However, there are lots of postings showing how to build Apache 2.2
> yourself under Visual Studio 2008, so that would be the workaround for
> running web2py on a Windows platform under Apache 2.2 when you are
> doing sftp or something using C/C++ code. Seehttp://comments.gmane.org/gmane.comp.apache.devel/43600where it
> routes_out = ((r'.*http://otherdomain.com.*/app/ctr(?P<any>.*)',
> r'\g<any>'),
>               (r'/app(?P<any>.*)', r'\g<any>'))
> ----------------------------------------------------------------------------------------------
> I created an ASP.NET 4.0 web application on IIS 7 whose Virtual
> Directory name is 'LTE1'
> In it, I used the Visual Studio 2010 wizard to create a basic web
> application (hello world roughly).
> In that web application I had to modify the web.config as per the
> documentation for  ManagedFusion.Rewriter
> I also created a 'bin' folder in LTE1 and copied the Managed Fusion
> dll into into it.
>
> The actual content of the .aspx pages in this .NET web app are
> irrelevant as this app is never
> rendered. Only its web.config is read and acted upon by Managed
> Fusion, to cause the request to be passed to
> the URL where web2py is running on Rocket at port 8000.
> ---------------------------------------------------------------------------------------------
> Now if I browse tohttp://138.85.50.99/LTE1
>
>  It hits IIS 7 and magically reroutes to my UETR web2py app athttp://138.85.50.99:8000/UETR?r=/LTE1
>
> More work is needed to refine it, but the basic functionality is
> shown.
>

Omi Chiba

unread,
Oct 12, 2011, 9:32:14 AM10/12/11
to web2py-users
David,

This kind of explains why pyodbc cannot run on apache under wsgi.

The below link solution may also work with you because I assume
Uniform server is built with correct compiler.

https://groups.google.com/group/web2py/browse_thread/thread/1cc544f52d9aeac4/eb79347e29582367#eb79347e29582367
Reply all
Reply to author
Forward
0 new messages