2012-12-03 7 views
0

Matthew A.Russell의 "Mining the Social Web"이라는 책을 기반으로 모듈 twitter 및 redis를 사용하여 Python의 Twitter 데이터 마이닝 응용 프로그램을 작성하고 있습니다. 내가 레디 스를 사용하지 않는 경우Twitter Python 프로그램 연결 오류

raise ConnectionError(self._error_message(e)) 
ConnectionError: Error 10061 connecting localhost:6379. No connection could be made because the target machine actively refused it. 

, 나는 모든 친구와 추종자의 ID를 얻을 수 있습니다 : 나는 친구와 레디 스 모듈을 사용하여 추종자의 정보를 얻으려고 할 때마다, 나에게 다음과 같은 오류를 제공합니다. 그러나 Redis는 데이터에 대해 특정 분석 작업을 수행해야합니다. 내 소스 코드는 다음과 같습니다 :

import json 
import locale 
import redis 
from prettytable import PrettyTable 

# Pretty printing numbers 
from twitter__util import pp 

# These functions create consistent keys from 
# screen names and user id values 
from twitter__util import getRedisIdByScreenName 
from twitter__util import getRedisIdByUserId 

SCREEN_NAME = "timoreilly" 

locale.setlocale(locale.LC_ALL, '') 

def calculate(): 
    r = redis.Redis() # Default connection settings on localhost 

    follower_ids = list(r.smembers(getRedisIdByScreenName(SCREEN_NAME, 
         'follower_ids'))) 

    followers = r.mget([getRedisIdByUserId(follower_id, 'info.json') 
         for follower_id in follower_ids]) 
    followers = [json.loads(f) for f in followers if f is not None] 

    freqs = {} 
    for f in followers: 
     cnt = f['followers_count'] 
     if not freqs.has_key(cnt): 
      freqs[cnt] = [] 

     freqs[cnt].append({'screen_name': f['screen_name'], 'user_id': f['id']}) 

    # It could take a few minutes to calculate freqs, so store a snapshot for later use 

    r.set(getRedisIdByScreenName(SCREEN_NAME, 'follower_freqs'), 
      json.dumps(freqs)) 

    keys = freqs.keys() 
    keys.sort() 

    print 'The top 10 followers from the sample:' 

    fields = ['Date', 'Count'] 
    pt = PrettyTable(fields=fields) 
    [pt.set_field_align(f, 'l') for f in fields] 

    for (user, freq) in reversed([(user['screen_name'], k) for k in keys[-10:] 
            for user in freqs[k]]): 
     pt.add_row([user, pp(freq)]) 

    pt.printt() 

    all_freqs = [k for k in keys for user in freqs[k]] 
    avg = reduce(lambda x, y: x + y, all_freqs)/len(all_freqs) 

    print "\nThe average number of followers for %s's followers: %s" \ 
     % (SCREEN_NAME, pp(avg)) 

# psyco can only compile functions, so wrap code in a function 

try: 
    import psyco 
    psyco.bind(calculate) 
except ImportError, e: 
    pass # psyco not installed 

calculate() 

모든 도움은 정말 감사하겠습니다. 감사!

답변

1

이것이 Redis가 실행되는 포트입니다. 내가 너라면, Redis 서버가 올바른 포트와 인터페이스에서 실행되고 있는지 다시 확인해 보겠습니다. 그를 테스트하려면 다음 설치 텔넷 클라이언트를했는데 할 수 있도록 :

$ telnet localhost 6379 

이 실패하면, 레디 스 클라이언트 라이브러리는 기본적으로 될 것으로 예상 경우 다음 레디 스 서버가 실제로 실행되지 않고, 이 경우 클라이언트에게 생성자 인수의 정확한 세부 정보를 제공해야합니다.

+0

어떻게하면됩니까? – Nathan822

+0

어떤 운영 체제를 사용하고 있습니까? 우분투 나 다른 데비안 유도체라면'sudo apt-get telnet을 설치하십시오' –

+0

Windows 7. 텔넷 클라이언트를 설치하고 telnet localhost 6379 명령을 실행했습니다. 실패하면. 출력은 다음과 같습니다. localhost에 연결 중 ... 포트 6379에서 호스트에 대한 통신을 열 수 없습니다 : 연결에 실패했습니다. – Nathan822