Колба + выпуск Gunicorn - PullRequest
       9

Колба + выпуск Gunicorn

0 голосов
/ 06 сентября 2018

У меня есть приложение Flask для работы со следующим открытием views:

@app.route('/login', methods=['GET', 'POST'])
def do_admin_login():

    if request.form['username'] != None:
        session['logged_in'] = True
    return redirect(url_for('index'))

, то:

@app.route("/index")
def index():     
    #Auth Step 1: Authorization
    url_args = "&".join(["{}={}".format(key,urllib.quote(val)) for key,val in auth_query_parameters.iteritems()])
    auth_url = "{}/?{}".format(SPOTIFY_AUTH_URL, url_args)

    return redirect(auth_url)

, то:

@app.route("/callback/q")
def callback():
    (long callback here)
    sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
    print "Getting user playlists..."
    playlist = get_user_playlist(USERNAME, sp)
    print "Getting playlists contents..."
    for i, p in enumerate(playlist):
      get_playlist_content(USERNAME, p, sp)
      print "Getting playlist # {} audio features...".format(i)
      get_playlist_audio_features(USERNAME, p, sp)
      print "Sorting..."

    return redirect(url_for('homepage'))

что в итоге должно привести приложение к:

@app.route('/')
def homepage():

    if not session.get('logged_in'):
        return render_template('login.html')
    else:        
        return render_template('homepage.html')

Выполнение этого с python app.py работает как заклинание, но если я запускаю с gunicorn следующим образом,

gunicorn -c gconfig.py app: app --log-level = debug

в терминале. Я вижу, что приложение работает через login(), index(), callback(), но останавливается на странице login, теперь перезагружается с пустыми формами, как если бы не было session['logged_in'].

вывод терминала:

127.0.0.1 - - [06/Sep/2018:03:28:07 -0300] "POST /login HTTP/1.1" 302 219 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
[2018-09-06 03:28:07 -0300] [18021] [DEBUG] GET /index
127.0.0.1 - - [06/Sep/2018:03:28:07 -0300] "GET /index HTTP/1.1" 302 703 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
[2018-09-06 03:28:07 -0300] [18023] [DEBUG] GET /callback/q
Getting user playlists...
Name: Discover Weekly, Number of songs: 30, Playlist ID: 37i9dQZEVXcRI2aS94C6hY 
Name: Time, Number of songs: 10, Playlist ID: 1qxOGf3xD3fDQs03kwKteg 
Name: Vocoder, Number of songs: 280, Playlist ID: 7nROSBznyIkVgjSdNaHDxm 
Getting playlists contents...
Getting playlist # 0 audio features...
Sorting...
Getting playlist # 1 audio features...
Sorting...
Getting playlist # 2 audio features...
Sorting...
127.0.0.1 - - [06/Sep/2018:03:28:16 -0300] "GET /callback/q?code=AQAataXciF5pUIiazCO-6zg3Vd6FX1RuaUJrrFxVgakcVjZkMtb36mi72KzSQBMF_GXgcgPIkFUGdkthnlX09REc4BXycZkAXc6-krXuXRtBUo4bNzjjGbyk-CDDdVl8e8Jj5O_OKs5IJtZ-Wiha647pv3YZgBhAyunjxQ6jid5lt8wXNf71XFxNLNeKnRX0ZH3fpN-z_UP4QXqIuaHoLnmgX9y3xJYem0udlVmM-Qz7QUWc3XEHwbZstygVQYKCXuyolzlGUhBQiOaI12OT8HnqKzZXbVsXQdKGR_9Lni7E46nM HTTP/1.1" 302 209 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
[2018-09-06 03:28:16 -0300] [18011] [DEBUG] GET /
127.0.0.1 - - [06/Sep/2018:03:28:16 -0300] "GET / HTTP/1.1" 200 799 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"

журнал конфигурации:

[2018-09-06 03:14:47 -0300] [18008] [DEBUG] Current configuration:
  proxy_protocol: False
  worker_connections: 1000
  statsd_host: None
  max_requests_jitter: 0
  post_fork: <function post_fork at 0x104710050>
  errorlog: -
  enable_stdio_inheritance: False
  worker_class: sync
  ssl_version: 2
  suppress_ragged_eofs: True
  syslog: False
  syslog_facility: user
  when_ready: <function when_ready at 0x1047101b8>
  pre_fork: <function pre_fork at 0x1047100c8>
  cert_reqs: 0
  preload_app: False
  keepalive: 5
  accesslog: -
  group: 20
  graceful_timeout: 30
  do_handshake_on_connect: False
  spew: False
  workers: 16
  proc_name: None
  sendfile: None
  pidfile: None
  umask: 0
  on_reload: <function on_reload at 0x1046eea28>
  pre_exec: <function pre_exec at 0x104710140>
  worker_tmp_dir: None
  limit_request_fields: 100
  pythonpath: None
  on_exit: <function on_exit at 0x1046f4c80>
  config: gconfig.py
  logconfig: None
  check_config: False
  statsd_prefix: 
  secure_scheme_headers: {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'}
  reload_engine: auto
  proxy_allow_ips: ['127.0.0.1']
  pre_request: <function pre_request at 0x1046f45f0>
  post_request: <function post_request at 0x1046f46e0>
  forwarded_allow_ips: ['127.0.0.1']
  worker_int: <function worker_int at 0x104710230>
  raw_paste_global_conf: []
  threads: 1
  max_requests: 0
  chdir: /Users/me/Documents/Code/Apps/app
  daemon: False
  user: 501
  limit_request_line: 4094
  access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
  certfile: None
  on_starting: <function on_starting at 0x1046ee8c0>
  post_worker_init: <function post_worker_init at 0x1046f4050>
  child_exit: <function child_exit at 0x1046f4848>
  worker_exit: <function worker_exit at 0x1046f49b0>
  paste: None
  default_proc_name: app:app
  syslog_addr: unix:///var/run/syslog
  syslog_prefix: None
  ciphers: TLSv1
  worker_abort: <function worker_abort at 0x1047102a8>
  loglevel: debug
  bind: ['127.0.0.1:8080']
  raw_env: []
  initgroups: False
  capture_output: False
  reload: False
  limit_request_field_size: 8190
  nworkers_changed: <function nworkers_changed at 0x1046f4b18>
  timeout: 120
  keyfile: None
  ca_certs: None
  tmp_upload_dir: None
  backlog: 2048
  logger_class: gunicorn.glogging.Logger
[2018-09-06 03:14:47 -0300] [18008] [INFO] Starting gunicorn 19.7.1
[2018-09-06 03:14:47 -0300] [18008] [DEBUG] Arbiter booted
[2018-09-06 03:14:47 -0300] [18008] [INFO] Listening at: http://127.0.0.1:8080 (18008)
[2018-09-06 03:14:47 -0300] [18008] [INFO] Using worker: sync
[2018-09-06 03:14:47 -0300] [18008] [INFO] Server is ready. Spawning workers
[2018-09-06 03:14:47 -0300] [18011] [INFO] Booting worker with pid: 18011
[2018-09-06 03:14:47 -0300] [18011] [INFO] Worker spawned (pid: 18011)
[2018-09-06 03:14:47 -0300] [18012] [INFO] Booting worker with pid: 18012
[2018-09-06 03:14:47 -0300] [18012] [INFO] Worker spawned (pid: 18012)
[2018-09-06 03:14:47 -0300] [18013] [INFO] Booting worker with pid: 18013
[2018-09-06 03:14:47 -0300] [18013] [INFO] Worker spawned (pid: 18013)
[2018-09-06 03:14:47 -0300] [18014] [INFO] Booting worker with pid: 18014
[2018-09-06 03:14:47 -0300] [18014] [INFO] Worker spawned (pid: 18014)
[2018-09-06 03:14:47 -0300] [18015] [INFO] Booting worker with pid: 18015
[2018-09-06 03:14:47 -0300] [18015] [INFO] Worker spawned (pid: 18015)
[2018-09-06 03:14:47 -0300] [18016] [INFO] Booting worker with pid: 18016
[2018-09-06 03:14:47 -0300] [18016] [INFO] Worker spawned (pid: 18016)
[2018-09-06 03:14:48 -0300] [18017] [INFO] Booting worker with pid: 18017
[2018-09-06 03:14:48 -0300] [18017] [INFO] Worker spawned (pid: 18017)
[2018-09-06 03:14:48 -0300] [18018] [INFO] Booting worker with pid: 18018
[2018-09-06 03:14:48 -0300] [18018] [INFO] Worker spawned (pid: 18018)
[2018-09-06 03:14:48 -0300] [18019] [INFO] Booting worker with pid: 18019
[2018-09-06 03:14:48 -0300] [18019] [INFO] Worker spawned (pid: 18019)
[2018-09-06 03:14:48 -0300] [18020] [INFO] Booting worker with pid: 18020
[2018-09-06 03:14:48 -0300] [18020] [INFO] Worker spawned (pid: 18020)
[2018-09-06 03:14:48 -0300] [18021] [INFO] Booting worker with pid: 18021
[2018-09-06 03:14:48 -0300] [18021] [INFO] Worker spawned (pid: 18021)
[2018-09-06 03:14:48 -0300] [18022] [INFO] Booting worker with pid: 18022
[2018-09-06 03:14:48 -0300] [18022] [INFO] Worker spawned (pid: 18022)
[2018-09-06 03:14:48 -0300] [18023] [INFO] Booting worker with pid: 18023
[2018-09-06 03:14:48 -0300] [18023] [INFO] Worker spawned (pid: 18023)
[2018-09-06 03:14:48 -0300] [18024] [INFO] Booting worker with pid: 18024
[2018-09-06 03:14:48 -0300] [18024] [INFO] Worker spawned (pid: 18024)
[2018-09-06 03:14:48 -0300] [18025] [INFO] Booting worker with pid: 18025
[2018-09-06 03:14:48 -0300] [18025] [INFO] Worker spawned (pid: 18025)
[2018-09-06 03:14:48 -0300] [18026] [INFO] Booting worker with pid: 18026
[2018-09-06 03:14:48 -0300] [18026] [INFO] Worker spawned (pid: 18026)
[2018-09-06 03:14:48 -0300] [18008] [DEBUG] 16 workers

Я не могу понять, в чем здесь проблема. Может ли кто-нибудь указать мне правильное направление?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...