pythonflaskpymongoiis-10wfastcgi

Error occurred while reading WSGI handler (Flask, Pymongo)


I have developed a web application with Flask that connects to a MongoDB database. Now that I have tried deploying to a Windows IIS environment. I have received an error when I display the application in the browser.

Here I indicate in the image the file tree of the "aplicativoflask" project. App.py is the main script.

enter image description here

I am using python 3.9.13 and Flask 1.1.2 and wfastcgi 3.0.0

Here I show the web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="App.py" />
            </files>
        </defaultDocument>
    </system.webServer>
    <appSettings>
        <add key="PYTHONPATH" value="C:\websites\applicativoflask" />
        <add key="WSGI_HANDLER" value="App.app" lockItem="false" />
    </appSettings>
</configuration>

I should point out that I installed Python with Anaconda (I didn't directly install python).

Here is the error I get:

Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "C:\Users\Administrator\anaconda3\lib\site-packages\wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "C:\Users\Administrator\anaconda3\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "C:\Users\Administrator\anaconda3\lib\site-packages\wfastcgi.py", line 616, in get_wsgi_handler
    raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "App.app" could not be imported: Traceback (most recent call last):
  File "C:\Users\Administrator\anaconda3\lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
    handler = __import__(module_name, fromlist=[name_list[0][0]])
  File "C:\websites\applicativoflask\.\App.py", line 6, in <module>
    from pymongo import MongoClient
  File "C:\Users\Administrator\anaconda3\lib\site-packages\pymongo\__init__.py", line 78, in <module>
    from pymongo.mongo_client import MongoClient  # noqa: F401
  File "C:\Users\Administrator\anaconda3\lib\site-packages\pymongo\mongo_client.py", line 59, in <module>
    from pymongo import (
  File "C:\Users\Administrator\anaconda3\lib\site-packages\pymongo\uri_parser.py", line 23, in <module>
    from pymongo.client_options import _parse_ssl_options
  File "C:\Users\Administrator\anaconda3\lib\site-packages\pymongo\client_options.py", line 24, in <module>
    from pymongo.pool import PoolOptions
  File "C:\Users\Administrator\anaconda3\lib\site-packages\pymongo\pool.py", line 22, in <module>
    import ssl
  File "C:\Users\Administrator\anaconda3\lib\ssl.py", line 99, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: DLL load failed while importing _ssl: The specified module could not be found.

I request your support to interpret the error and provide a solution. Big thanks for any comment.


Solution

  • Please try to copy the following files from directory anaconda3\Library\bin to anaconda3/DLLs.

    libcrypto-1_1-x64.dll

    libssl-1_1-x64.dll

    Then recall the command and open the webpage.