2015-05-31 16 views
-1

當運行我的服務器我得到以下錯誤試圖捕捉來自Twitter的主題標籤數據飼料使用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 

我試圖運行頁面的背景劇本,但我得到了同樣的錯誤代碼,該井號標籤確實打印在控制檯窗口中,我試圖將推文轉化爲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 
+0

stream.filter(track = [「lol」])輸出是什麼? –

+0

監視與LOL匹配的twiter上的所有主題標籤(#LOL) – glls

+1

您是否曾經想過發生異常是出於某種原因?只抓住他們'通過'必然會導致問題。 –

回答

0

所以,我設法捕捉一個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)