与Flask socketio一起流动的Tweepy

时间:2018-01-11 19:18:09

标签: python flask-socketio

我希望在收到推文时将实时的推文流发送给客户端。

Runtime Error: Working outside of request context

但是在运行时遇到# Create a link (h4xdir) to a directory: goat h4xdir ~/Documents/dev # Follow a link to change a directory: cd h4xdir # Follow a link (and don't stop there!): cd h4xdir/awesome-project # Go up the filesystem tree with '...' (same as `cd ../../`): cd ... # List all your links: goat list # Delete a link (or more): goat delete h4xdir lojban # Delete all the links which point to directories with the given prefix: goat deleteprefix $HOME/Documents # Delete all saved links: goat nuke # Delete broken links: goat fix 错误。我如何做我想做的事情?谢谢。

1 个答案:

答案 0 :(得分:1)

emit()中的tweet_received()调用没有客户端上下文来知道将数据发送到何处。

您可以通过添加设置命名空间和事件接收者的其他参数来修复它。例如:

@staticmethod
def tweet_received(text):
    emit('tweet_response', {'text': text}, broadcast=True, namespace='/')

此版本将发送给/命名空间上的所有客户端。您可能需要将其更改为最适合您的应用程序的内容,但希望您明白这一点。