librelist archives

« back to archive

Flask-CouchDB Error

Flask-CouchDB Error

From:
Date:
2010-10-07 @ 21:16
Hi,

I tried to run a Flask-CouchDB example which Matthew Frazier /  
leafstorm 's guestbook.py on bitbucket. And I take this error message.  
Any suggestions ?


*-*-*-*-

IndexError: list index out of range
Traceback (most recent call last)
     *
       File  
"/usr/local/lib/python2.6/dist-packages/Flask-0.4-py2.6.egg/flask.py",  
line 1508, in __call__
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] return self.wsgi_app(environ,  
start_response)
     *
       File  

"/usr/local/lib/python2.6/dist-packages/Werkzeug-0.6.2-py2.6.egg/werkzeug/wsgi.py",
line 406, in  
__call__
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] return self.app(environ, start_response)
     *
       File  
"/usr/local/lib/python2.6/dist-packages/Flask-0.4-py2.6.egg/flask.py",  
line 1453, in wsgi_app
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] response =  
self.make_response(self.handle_exception(e))
     *
       File  
"/usr/local/lib/python2.6/dist-packages/Flask-0.4-py2.6.egg/flask.py",  
line 1448, in wsgi_app
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] rv = self.preprocess_request()
     *
       File  
"/usr/local/lib/python2.6/dist-packages/Flask-0.4-py2.6.egg/flask.py",  
line 1395, in preprocess_request
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] rv = func()
     *
       File  

"/usr/local/lib/python2.6/dist-packages/Flask_CouchDB-0.2.1-py2.6.egg/flaskext/couchdb.py",
line 154, in  
request_start
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] self.sync(current_app)
     *
       File  

"/usr/local/lib/python2.6/dist-packages/Flask_CouchDB-0.2.1-py2.6.egg/flaskext/couchdb.py",
line 137, in  
sync
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] callback=getattr(self,  
'update_design_doc', None)
     *
       File  

"/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/design.py",
line 195, in  
sync_many
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] db.update(docs)
     *
       File  

"/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/client.py",
line 746, in  
update
        [Display the sourcecode for this frame]  [Open an interactive  
python shell in this frame] doc = documents[idx]

*-*-*-*-*-

Re: [flask] Flask-CouchDB Error

From:
Date:
2010-10-08 @ 18:51
I tried python console and I take this error. I think I should make  
some configuration before testing, but I don't know what they are and  
I can't find Flask-CouchDB documentaion. Any ideas?


Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> from flask import Flask, render_template, flash, request, redirect, url_for
>>> from flask import g
>>> from flaskext.couchdb import (CouchDBManager, Document, TextField,
...                               DateTimeField, ViewField, paginate)
>>>
>>>
>>> # application setup
... app = Flask(__name__)
>>>
>>>
>>> # config
... COUCHDB_SERVER = 'http://localhost:5984/'
>>> COUCHDB_DATABASE = 'example-guestbook'
>>> SECRET_KEY = 'xxx'
>>>
>>> app.config.from_object(__name__)
>>>
>>>
>>> # model
... class Signature(Document):
...     doc_type = 'signature'
...
...     message = TextField()
...     author = TextField()
...     time = DateTimeField(default=datetime.datetime.now)
...
...     all = ViewField('guestbook', '''
...         function (doc) {
...             if (doc.doc_type == 'signature') {
...                 emit(doc.time, doc);
...             };
...         }''', descending=True)
...
>>>
>>> manager = CouchDBManager()
>>> manager.add_document(Signature)
>>> manager.setup(app)
>>> signature = Signature(message='test', author='test')
>>> signature.store()
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File  

"/usr/local/lib/python2.6/dist-packages/Flask_CouchDB-0.2.1-py2.6.egg/flaskext/couchdb.py",
line 207, in  
store
     return mapping.Document.store(self, db or g.couch)
   File  

"/usr/local/lib/python2.6/dist-packages/Werkzeug-0.6.2-py2.6.egg/werkzeug/local.py",
line 347, in  
__getattr__
     return getattr(self._get_current_object(), name)
   File  

"/usr/local/lib/python2.6/dist-packages/Werkzeug-0.6.2-py2.6.egg/werkzeug/local.py",
line 306, in  
_get_current_object
     return self.__local()
   File  
"/usr/local/lib/python2.6/dist-packages/Flask-0.4-py2.6.egg/flask.py",  
line 1516, in <lambda>
     g = LocalProxy(lambda: _request_ctx_stack.top.g)
AttributeError: 'NoneType' object has no attribute 'g'
>>>




Re: [flask] Flask-CouchDB Error

From:
Ron DuPlain
Date:
2010-10-08 @ 19:26
On Fri, Oct 8, 2010 at 2:51 PM,  <yilmazmehmet@itu.edu.tr> wrote:
>    Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
>    [GCC 4.3.3] on linux2
>    Type "help", "copyright", "credits" or "license" for more information.
>    ...
>    >>> signature.store()
>    Traceback (most recent call last):
>    ...
>    g = LocalProxy(lambda: _request_ctx_stack.top.g)
>    AttributeError: 'NoneType' object has no attribute 'g'
>    >>>

You need to run in an application request context.  A couple options:

1. Use `python manage.py shell` in Flask-Script, instead of `python` directly.

    http://packages.python.org/Flask-Script/

2. With the `app` instance you created above, continue with:

   >>> import code
   >>> with app.test_request_context():
   ...     code.interact(local=dict(app=app))
   ...

Then continue interacting inside an app test request context.

-Ron

Re: [flask] Flask-CouchDB Error

From:
Date:
2010-10-09 @ 14:37
Thanks for your reply, Ron.

I also want to see running this example on browser. I type 'python  
guestbook.py' command to run this application. In other command prompt  
tab I run 'couchdb' command and I can take response from  
http://localhost:5984/. Should I do something else ?

Alinti Ron DuPlain <ron.duplain@gmail.com>

> On Fri, Oct 8, 2010 at 2:51 PM,  <yilmazmehmet@itu.edu.tr> wrote:
>>    Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
>>    [GCC 4.3.3] on linux2
>>    Type "help", "copyright", "credits" or "license" for more information.
>>    ...
>>    >>> signature.store()
>>    Traceback (most recent call last):
>>    ...
>>     g = LocalProxy(lambda: _request_ctx_stack.top.g)
>>    AttributeError: 'NoneType' object has no attribute 'g'
>>    >>>
>
> You need to run in an application request context.  A couple options:
>
> 1. Use `python manage.py shell` in Flask-Script, instead of `python`  
> directly.
>
>     http://packages.python.org/Flask-Script/
>
> 2. With the `app` instance you created above, continue with:
>
>    >>> import code
>    >>> with app.test_request_context():
>    ...     code.interact(local=dict(app=app))
>    ...
>
> Then continue interacting inside an app test request context.
>
> -Ron
>
>


Re: [flask] Flask-CouchDB Error

From:
Ron DuPlain
Date:
2010-10-11 @ 14:32
On Sat, Oct 9, 2010 at 10:37 AM,  <yilmazmehmet@itu.edu.tr> wrote:
> Thanks for your reply, Ron.
>
> I also want to see running this example on browser. I type 'python
> guestbook.py' command to run this application. In other command prompt
> tab I run 'couchdb' command and I can take response from
> http://localhost:5984/. Should I do something else ?

I'm not sure I understand the question.  With CouchDB running, you
should be able to interact with your app from the Python interpreter
through Flask-Script or `with app.test_request_context` directly
(which Flask-Script does for you).  Have you tried this?

The interpreter can help you get up and running.  From there, set up
your Flask() instance in guestbook.py and run via `python manage.py
runserver` (via Flask-Script) or put `app.run()` in guestbook.py and
run `python guestbook.py` as shown here::

    http://flask.pocoo.org/docs/quickstart/

This will start a development server on port 5000.  Point your browser
to http://localhost:5000.

-Ron


> Alinti Ron DuPlain <ron.duplain@gmail.com>
>
>> On Fri, Oct 8, 2010 at 2:51 PM,  <yilmazmehmet@itu.edu.tr> wrote:
>>>    Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
>>>    [GCC 4.3.3] on linux2
>>>    Type "help", "copyright", "credits" or "license" for more information.
>>>    ...
>>>    >>> signature.store()
>>>    Traceback (most recent call last):
>>>    ...
>>>     g = LocalProxy(lambda: _request_ctx_stack.top.g)
>>>    AttributeError: 'NoneType' object has no attribute 'g'
>>>    >>>
>>
>> You need to run in an application request context.  A couple options:
>>
>> 1. Use `python manage.py shell` in Flask-Script, instead of `python`
>> directly.
>>
>>     http://packages.python.org/Flask-Script/
>>
>> 2. With the `app` instance you created above, continue with:
>>
>>    >>> import code
>>    >>> with app.test_request_context():
>>    ...     code.interact(local=dict(app=app))
>>    ...
>>
>> Then continue interacting inside an app test request context.
>>
>> -Ron
>>
>>
>
>
>
>