尝试使用 tweepy 从 Twitter 主题标签提要中捕获数据

Trying to capture data from twitter hashtag feeds using tweepy

当 运行 我的服务器出现以下错误时

ValueError at /
The view hashtrack.views.index didn't return an HttpResponse object. It returned None instead.
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.8.2
Exception Type: ValueError
Exception Value:    
The view hashtrack.views.index didn't return an HttpResponse object. It returned None instead.
Exception Location: C:\Python34\lib\site-packages\django\core\handlers\base.py in get_response, line 151
Python Executable:  C:\Python34\python.exe
Python Version: 3.4.3
Python Path:    
['C:\Users\torjeli\tweesh',
 'C:\Python34\lib\site-packages\setuptools-15.2-py3.4.egg',
 'C:\Python34\lib\site-packages\distribute-0.6.49-py3.4.egg',
 'C:\Python34\lib\site-packages\cython-0.22-py3.4-win32.egg',
 'C:\Python34\lib\site-packages\scrapy-0.24.6-py3.4.egg',
 'C:\Python34\lib\site-packages\six-1.9.0-py3.4.egg',
 'C:\Python34\lib\site-packages\cssselect-0.9.1-py3.4.egg',
 'C:\Python34\lib\site-packages\pyopenssl-0.15.1-py3.4.egg',
 'C:\Windows\system32\python34.zip',
 'C:\Python34\DLLs',
 'C:\Python34\lib',
 'C:\Python34',
 'C:\Python34\lib\site-packages',
 'C:\Python34\lib\site-packages\win32',
 'C:\Python34\lib\site-packages\win32\lib',
 'C:\Python34\lib\site-packages\Pythonwin']
Server time:    Sun, 31 May 2015 18:59:22 -0400

我已经尝试 运行 页面背景上的脚本,但我得到了相同的错误代码,主题标签确实打印在控制台中 window,我正在尝试获取将推文存入 csv 文件以备后用。

from django.shortcuts import render_to_response
from django.http import HttpResponse
from tweepy import *


CKey = 'xxxxx'           #API Key
ConSec = 'xxxxx'         #Consumer Secret
AccTok = 'xxxxx'         #Access Token
AccTSec = 'xxxxx'        #Access Token Secret


class StdOutListener(StreamListener):

    def on_status(self, status):

        print(status.text)
        return True

    def on_error(self, status):

        print(status)


def index(request):
    try:
        listener = StdOutListener()
        auth = OAuthHandler(CKey, ConSec)
        auth.set_access_token(AccTok, AccTSec)
        stream = Stream(auth, listener)
        gimme = stream.filter(track=["lol"])
        return HttpResponse(gimme)

        #return render_to_response('index.html')
    except RuntimeError:
        pass

所以,我设法在 CSV 上捕获了数据,但是当进程 运行 时页面没有加载。...但是我确实得到了一个 CSV 文件,其中包含我想要的所有信息。

from django.http import HttpResponse
from tweepy import *



CKey = 'xxxxx'           #API Key
ConSec = 'xxxxx'         #Consumer Secret
AccTok = 'xxxxx'         #Access Token
AccTSec = 'xxxxx'        #Access Token Secret


class StdOutListener(StreamListener):

def on_status(self, status):
    try:

        hashdb = open("hashtag.csv", 'a')
        hashdb.write(status.text)
        hashdb.write('\n')
        hashdb.close()
    except BaseException:
        print("could not process")
def on_error(self, status_code):
    print(status_code)
    return status_code


def index(request):

    listener = StdOutListener()
    auth = OAuthHandler(CKey, ConSec)
    auth.set_access_token(AccTok, AccTSec)
    stream = Stream(auth, listener)
    gimme = stream.filter(track=["lol"])
    html = "<html><body>It is now %s.</body></html>" % gimme
    return HttpResponse(html)