Уведомления

Группа в Telegram: @pythonsu
  • Начало
  • » Web
  • » Bottle + Cork "ProgrammingError: SQLite objects created in a thread...." [RSS Feed]

#1 Май 12, 2014 19:27:42

lnkr-a
Зарегистрирован: 2014-04-14
Сообщения: 10
Репутация: +  0  -
Профиль   Отправить e-mail  

Bottle + Cork "ProgrammingError: SQLite objects created in a thread...."

Добрый вечер.

Пытаюсь настроить аутентификацию в Bottle с помощью Cork.

import bottle
from cork import Cork
from operator import itemgetter
from py2neo import neo4j, node, cypher
from pip._vendor.colorama import initialise
<...> #здесь метод query задаётсяю это к делу отношения не имеет
from cork.backends import SQLiteBackend
try:
    sqldb = SQLiteBackend('example.db', initialize=True)
except:
    sqldb = SQLiteBackend('example.db', initialize=False)
aaa = Cork(backend=sqldb)
authorize = aaa.make_auth_decorator(fail_redirect="/login", role="user")
@bottle.route('/')
@bottle.view('login')
def index():
    #return "<a href='/person_list'>List of persons</a>"
    return
@bottle.route('/person_list')
@bottle.view('person_list')
def list():
    html_list = str(aaa.current_user) + "<ul>"
    persons = query("MATCH (n:person) RETURN (n) ORDER BY n.name")
    for person in persons:
        html_list += bottle.template('person_list_entry', id=person._id, name=person['name'], nickname=person['nickname'])
    html_list += '</ul>'
    return dict(list=html_list)
@bottle.post('/login')
def login():
    username = bottle.request.forms.get('username')
    password = bottle.request.forms.get('password')
    aaa.login(username, password, success_redirect='/person_list', fail_redirect='/person_list') 

в результате в логах апача имеем:
Traceback (most recent call last):, referer: http://mabimarket/
File “C:\\Python27\\lib\\site-packages\\bottle.py”, line 862, in _handle, referer: http://mabimarket/
return route.call(**args), referer: http://mabimarket/
File “C:\\Python27\\lib\\site-packages\\bottle.py”, line 1729, in wrapper, referer: http://mabimarket/
rv = callback(*a, **ka), referer: http://mabimarket/
File “D:\\Server\\domains\\mabimarket\\index.py”, line 50, in login, referer: http://mabimarket/
aaa.login(username, password, success_redirect='/person_list', fail_redirect='/person_list'), referer: http://mabimarket/
File “C:\\Python27\\lib\\site-packages\\cork\\cork.py”, line 102, in login, referer: http://mabimarket/
if username in self._store.users:, referer: http://mabimarket/
File “C:\\Python27\\lib\\site-packages\\cork\\sqlite_backend.py”, line 52, in __contains__, referer: http://mabimarket/
row = self._backend.fetch_one(query), referer: http://mabimarket/
File “C:\\Python27\\lib\\site-packages\\cork\\sqlite_backend.py”, line 230, in fetch_one, referer: http://mabimarket/
return self._connection.execute(query).fetchone(), referer: http://mabimarket/
ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 5780 and this is thread id 10120, referer: http://mabimarket/

Смысл я понимаю. Вопрос в том, как с этим справиться. В каком моменте создавать подключение к базе данных? Ведь aaa = Cork(backend=sqlb) должна быть уровня модуля.

Спасибо.

Офлайн

  • Начало
  • » Web
  • » Bottle + Cork "ProgrammingError: SQLite objects created in a thread...."[RSS Feed]

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version