2017-04-25 2 views
1

Ich habe Schwierigkeiten, Passagier zur Arbeit mit Kolben zu bekommen. Ich betreibe die Flask-Site auf DreamHost in einem virutalenv mit Python 3.5.2. Die Anwendung sollte Eingaben von einer Abfragezeichenfolge in der URL erhalten, eine serverseitige JSON-Datei analysieren, die JSON-Datei nach der Abfragezeichenfolge durchsuchen, die JSON-Datei neu formatieren und sie an den Client zurücksenden. Stattdessen gibt es mir den Fehlercode 500. Hier ist mein Code. Bitte verzeihen Sie alle Anrufe der Protokollierungsfunktion. Ich habe getan, was ich kann, indem ich mich umschaute.Passagier läuft Flask Website zurück 500 Fehler auf Dreamhost

import logging 
logging.basicConfig(filename='wsgi_flask.log', level=logging.DEBUG) 
try: 
    import sys, os 

    logging.info('line 7') 

    VENV = os.path.join(os.environ['HOME'], '.pyenv', 'versions', '3.5.2', 'envs', 'flask') 
    INTERP = os.path.join(VENV, 'bin', 'python') 

    logging.info('line 12') 

    if sys.executable != INTERP: 
     os.execl(INTERP, INTERP, *sys.argv) 

    logging.info('line 17') 

    sys.path.append(VENV) 
    sys.path.append(os.path.join(VENV, 'lib', 'python3.5', 'site-packages')) 
    sys.path.append(os.path.join(os.environ['HOME'], 'api.example.com')) 

    logging.info('line 23') 

    # INTERP = os.path.join(os.environ['HOME'], '.pyenv', 'versions', 'flask', 'bin', 'python') 
    # if sys.executable != INTERP: 
    #  os.execl(INTERP, INTERP, *sys.argv) 
    # sys.path.append(os.getcwd()) 
    from paste.exceptions.errormiddleware import ErrorMiddleware 

    logging.info('line 31') 

    # import argparse 
    import json 

    logging.info('line 36') 

    from flask import (Flask, abort, g, jsonify, make_response, redirect, 
        render_template, render_template_string, request, url_for, Response) 

    logging.info('line 41') 

    # parser = argparse.ArgumentParser() 
    # parser.add_argument('-d', '--debug', action='store_true') 
    # apargs = parser.parse_args() 

    # def debugLog(*args): 
    #  if apargs.debug: 
    #   for i in args: 
    #    print(i) 

    application = Flask(__name__) 

    logging.info('line 54') 

    @application.route('/') 
    def index(): 
     logging.info('line 58') 
     # if apargs.debug: 
     #  data = json.load(open('/path/to/test.json', 'rb')) 
     # else: 
     logging.info('line 62') 
     try: 
      logging.info('line 64') 
      data = json.load(open('/path/to/test.json', 'rb')) 
      logging.info('line 66') 
     except: 
      logging.info('line 68') 
      logging.warning('Is it the JSON?') 
      raise('Error whilst loading JSON') 
     logging.info('line 71') 
     getForm = request.args.get('search') or '' 
     logging.info('line 73') 

     # debugLog(data, getForm) 

     jsonData = "" 
     logging.info('line 78') 
     for d in data: 
      logging.info('line 80 (for loop)') 
      # debugLog(d) 
      if getForm in d['text']: 
       logging.info('line 83 (for loop)') 
       jsonData = jsonData + str(d) + ',' 
       logging.info('line 85 (for loop)') 
      logging.info('line 86 (for loop)') 
     logging.info('line 87 (out of loop)') 
     # debugLog(jsonData) 

     jsonData = str(jsonData) 
     logging.info('line 91') 
     jsonData = jsonData[:-1] 
     logging.info('line 93') 
     jsonData = jsonData.replace("'", '"') 
     logging.info('line 95') 
     jsonData = '[' + jsonData + ']' 
     logging.info('line 97') 

     # debugLog('\n', jsonData) 
     return Response(jsonify(json.loads(jsonData)), mimetype='application/json') 
     logging.info('line 101 (this should not show)') 

     @application.errorhandler(500) 
     def error(e): 
      logging.warning(e + '\n\n\n What\'s happening here') 
      return str(e) 
     logging.info('line 107') 
     application = ErrorMiddleware(application, debug=True, error_log='tmp/wsgi_error.log') 
     logging.info('line 109') 

    # if apargs.debug: 
    #  application.run(host='0.0.0.0', debug=True, port=80) 
except: 
    logging.warning('line 114 (beginning of outer most try-except)') 
    import sys, os 
    logging.warning('line 116') 

    from traceback import format_list, extract_tb 
    logging.warning('line 119') 
    (extype, value, trace) = sys.exc_info() 
    logging.warning('line 121') 

    sys.stderr.buffer.write("%s:%s\n%s" % (extype, value,''.join(format_list(extract_tb(trace))))) 
    logging.warning('line 124 (EOF)') 

Das ist mein Verzeichnisbaum:

. 
|-- .python-version 
|-- public 
| |-- .htaccess 
| |-- favicon.gif 
| |-- favicon.ico 
| |-- passenger_wsgi.py 
| `-- quickstart.html 
`-- tmp 
    `-- restart.txt 

Und das ist meine .htaccess:

PassengerPython /home/dh_user/.pyenv/versions/3.5.2/envs/flask/bin/python 

<VirtualHost *:80> 
    # This Flask web app will use Python 3.0 
    ServerName api.example.com 
    DocumentRoot /home/dh_user/api.example.com/public 
</VirtualHost> 

ich unten alle Führungen verwendet haben, um Hilfe und Referenz:

https://help.dreamhost.com/hc/en-us/articles/215769548-Passenger-and-Python-WSGI https://www.phusionpassenger.com/library/walkthroughs/start/python.html https://www.byteconsole.com/get-flask-up-and-running-on-a-dreamhost-server-with-passenger/

Bearbeiten: Dreamhost erlaubt mir nicht, die Passenger-Protokolle auf einem freigegebenen Host anzuzeigen. Das Beste, was ich dir geben kann ist mein error.log, die bei jeder Anfrage, gibt mir

[Wed Apr 26 13:52:51 2017] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: 
[Wed Apr 26 13:52:51 2017] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: internal_error.html 

Edit 2: Ich bin mit dem Einfügen Python Modulfehler von Flask zu sammeln und es gibt mir diese:

File '/home/dh_user/.pyenv/versions/3.5.2/envs/flask/lib/python3.5/site-packages/paste/exceptions/errormiddleware.py', line 224 in next 
    return self.app_iterator.next() 
AttributeError: 'ClosingIterator' object has no attribute 'next' 
+1

Bitte senden Sie das Traceback. – stamaimer

Antwort

0

Nun, ich habe es offenbar behoben. Was ich mich erinnern kann, ist das Entfernen von Paste und das Ausführen einiger Dinge danach.

Verwandte Themen