python:逗号-python twitter无法通过从数据库表中获取的用户名查找用户的潜在问题

python:逗号-python twitter无法通过从数据库表中获取的用户名查找用户的潜在问题,python,twitter,sqlite,python-twitter,Python,Twitter,Sqlite,Python Twitter,首先,, 以下是我的代码: ################################################################# #PART I: import "twitter_handle.csv" file into SQL DB ################################################################# # the name of the SQL DB table is TWITTER_HANDLE

首先,, 以下是我的代码:

#################################################################
#PART I: import "twitter_handle.csv" file into SQL DB
#################################################################

# the name of the SQL DB table is TWITTER_HANDLE  
import csv
import sqlite3 

# Create the database
connection = sqlite3.connect(':memory:')
cursor = connection.cursor()
# Create the table
cursor.execute('DROP TABLE IF EXISTS TWITTER_HANDLE')
cursor.execute('CREATE TABLE TWITTER_HANDLE (twitter_handle TEXT) ')
connection.commit()
# convert twitter_handle.csv file from the desktop to tab-deliminted file
with open('/Users/hyunjincho/Desktop/twitter_handle.csv', 'rb') as ifile:
     reader1 = csv.reader(ifile)
     for row in reader1:
       cursor.execute('INSERT INTO  TWITTER_HANDLE VALUES (?)', row )

ifile.close()

cursor.execute('DELETE FROM TWITTER_HANDLE WHERE twitter_handle = "NA"')
connection.commit()    

#remove string character(i.e. remove u's) check how the table looks like   
#check how the table looks like
cursor.execute('SELECT twitter_handle FROM TWITTER_HANDLE')
connection.text_factory = str
cursor.execute('SELECT twitter_handle FROM TWITTER_HANDLE')   
print cursor.fetchall()

#########################################################
#PART II: Gain and confirm authorization to twitter
##########################################################
import json
import twitter
import sys
sys.path.append("/Users/hyunjincho/Documents/Modules")
print sys.path

#gain authorization to twitter
consumer_key = 'a'
consumer_secret = 'b'
oauth_token = 'c'
oauth_token_secret = 'd'
auth = twitter.oauth.OAuth(consumer_key, consumer_secret, oauth_token, oauth_token_secret)
api=twitter.Twitter(auth=auth)


##########################################################################
#PART III: Twitter manipuation using tables from PART II
##########################################################################
import time

for element in cursor.execute('SELECT twitter_handle FROM TWITTER_HANDLE'):       
    #time.sleep(5) #to get around the rate limit
    element =', '.join( element )     
    element.replace(",","")
    start = api.users.lookup()
这些代码本身不会在语法方面产生任何错误。但是,出现以下错误:

---------------------------------------------------------------------------
TwitterHTTPError                          Traceback (most recent call last)
<ipython-input-7-e4934ec45f7a> in <module>()
    6     #element.replace(",","")
    7     #print cursor.fetchone()
--> 8     start = api.users.lookup()
    9 

/Users/hyunjincho/anaconda/python.app/Contents/lib/python2.7/site-packages/twitter/api.pyc 
in __call__(self, **kwargs)
    202 
    203         req = urllib_request.Request(uriBase, body, headers)
--> 204         return self._handle_response(req, uri, arg_data, _timeout)
    205 
    206     def _handle_response(self, req, uri, arg_data, _timeout=None):

/Users/hyunjincho/anaconda/python.app/Contents/lib/python2.7/site-packages/twitter/api.pyc
in _handle_response(self, req, uri, arg_data, _timeout)
    233                 return []
    234             else:
--> 235                 raise TwitterHTTPError(e, uri, self.format, arg_data)
    236 
    237 class Twitter(TwitterCall):

TwitterHTTPError: Twitter sent status 401 for URL: 1.1/users/lookup.json using parameters:    
(oauth_consumer_key=35WksHhvf3MnVjJjzciEfl84PJkGNWDwvZZtE72ix4&oauth_nonce=
9964503666055746364&oauth_signature_method=HMAC-       
SHA1&oauth_timestamp=1382631721&oauth_token=xdbX1g21REs0MPxofJPcFw&oauth_version=1.0&
oauth_signature=E%2F722PPfPcn64LqbPMdpo4KiK0o%3D)
details: {"errors":[{"message":"Invalid or expired token","code":89}]}
它给出了类似于:

 ('3Degrees',) #<----note the comma at the end
 ('aandrsolar',)

('3Degrees',)#
('3Degrees',)
是一个元组(一个具有一个元素的元组)。定义元组的是逗号,而不是括号。是的……这是真的……那么我得到错误的原因是什么?我将如何解决它?错误表明oauth_令牌(或oauth_令牌_secret)不好。您确定您提供的初始数据正确吗?您是否尝试通过interperter运行代码的身份验证部分?我尝试了…并多次更改令牌以获得新的令牌…不起作用…通过interperter运行时是否起作用?(即与命令行交互)
 ('3Degrees',) #<----note the comma at the end
 ('aandrsolar',)
 ('3degrees')  #<---no comma at the end
 ('aandrsolar')