PaulGlass
PaulGlass

Reputation: 43

Flask Error with wsgi_handler

I am trying to use WSGI on Windows Server to run a simple flask app. I keep running into the following error:

Error occurred while reading WSGI handler: Traceback (most recent call last): File "c:\inetpub\wwwroot\test_site\wfastcgi.py", line 711, in main env, handler = read_wsgi_handler(response.physical_path) File "c:\inetpub\wwwroot\test_site\wfastcgi.py", line 568, in read_wsgi_handler return env, get_wsgi_handler(handler_name) File "c:\inetpub\wwwroot\test_site\wfastcgi.py", line 551, in get_wsgi_handler raise ValueError('"%s" could not be imported' % handler_name) ValueError: "app.app" could not be imported StdOut: StdErr

For my site I configured a handler to call the FastCGIModule from Microsoft Web Platform installer

My app file looks as such:

from flask import Flask, request, jsonify
from analyzers import analyzer
import write_log

app = Flask(__name__)

@app.route("/")
def test():
    return "Test load"

@app.route('/analyze', methods=['POST'])
def parse():
    text = request.json['text']
    name = request.json['name']
    model = request.json['model']
    try:
        convert_flag = request.json['convert_flag']
    except KeyError:
        convert_flag = False
    results= analyzer(text, name, model, convert_dose=convert_flag)
    write_log.write_log(text, name, model, results)
    return jsonify(results)

if __name__ == "__main__":
    app.run()

If I comment out the custom import of my analyzer script and my write_log script along with the POST method things will run, so I know I must be messing something up there.

Does anybody have any suggestions?

Thanks in advance.

Paul

Upvotes: 3

Views: 3923

Answers (1)

Renato Byrro
Renato Byrro

Reputation: 3784

I had the same issue and the problem was with a third-party library. What's causing your problem is certainly something different, but here's something I did to identify my issue and may help you as well:

  1. Open wfastcgi.py
  2. Locate the method get_wsgi_handler (probably on line 519)
  3. There's a try/except inside a while module_name statement
  4. Add raise to the end of the except block and save the file, like this:

    except ImportError:
        ...
        raise
    
  5. Access your website URL again and check your logs, they now should be more detailed about what caused the ImportError and will point you in the right direction to fix the issue

Upvotes: 1

Related Questions