python - Flask: cannot import name 'app' -


trying run python file updater.py ssh server , run commands every few set intervals or so. i'm using apscheduler run function update_printer() __init__.py. got working outside of application context error suggested import app __init__.py. isn't working out well. keep getting cannot import name 'app' error.

app.py

from queue_app import app  if __name__ == '__main__':     app.run(debug=true) 

__init__.py

from flask import flask, render_template apscheduler.schedulers.background import backgroundscheduler queue_app.updater import update_printer app = flask(__name__) app.config.from_object('config')  @app.before_first_request def init():     sched = backgroundscheduler()     sched.start()     sched.add_job(update_printer, 'interval', seconds=10)  @app.route('/') def index():     return render_template('index.html') 

updater.py

import paramiko import json queue_app import app  def update_printer():     ssh = paramiko.sshclient()     ssh.set_missing_host_key_policy(paramiko.autoaddpolicy())     ssh.connect(app.config['ssh_server'], username = app.config['ssh_username'], password = app.config['ssh_password'])  ... 

file structure

queue/    app.py    config.py    queue_app/       __init__.py       updater.py 

error

traceback (most recent call last):   file "app.py", line 1, in <module>     queue_app import app   file "/users/name/queue/queue_app/__init__.py", line 3, in <module>     queue_app.updater import update_printer   file "/users/name/queue/queue_app/updater.py", line 3, in <module>     queue_app import app importerror: cannot import name 'app' 

what need able app.config updater.py , avoid "working outside of application context error" if ran apscheduler?

it's circular dependency, import updater in __init__.py file. in flask setup, app created in app.py.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -