i have the next code:
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
import tweepy
consumer_key=""
consumer_secret=""
access_key = ""
access_secret = ""
def twitterfeed():
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
statuses = tweepy.Cursor(api.friends_timeline).items(20)
for status in statuses:
return list(str(status.text))
this twitterfeed() method is working on the bash/console, and shows the latest tweets of me and my subscribers. But when i want to show this tweets on the page:
if __name__ == '__main__':
config = Configurator()
config.add_route('hello', '{name}')
config.add_view(twitterfeed(), route_name='hello')
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()
it shows me pyramid.exceptions.ConfigurationExecutionError: <type 'exceptions.AttributeError'>: 'list' object has no attribute '__module__' error
in:
Line 24
how can i fix it? if you have working example from django, it can help me.
You should register the function, not the result of the function:
otherwise you are trying to register the list returned by
twitterfeedas a view instead.Note that your function needs to accept a
requestparameter too; and it’ll have to return a response object too. Change it to:I’ve taken the liberty of encoding the tweets to UTF8 instead of leaving it up to Python to pick a default encoding for them (which will lead to UnicodeEncodeError exceptions if there are any international characters in your tweets).
You really want to read up on pyramid views before you continue.
As an aside, your command-line version returned only first tweet as a list of individual characters (
return list(str(status.text))).