2012-12-12 34 views
0

使用twitter-1.9.0(http://pypi.python.org/pypi/twitter/1.9.0) 我想發送狀態消息,但無法做到這一點。下面是代碼片段。無法發送狀態消息到Twitter使用python3.3及其包twitter-1.9.0

import twitter as t 

# consumer and authentication key values are provided here. 

def tweet(status): 
    if len(status) > 140 : 
     raise Exception ('Status message too long !!!') 
    authkey = t.Twitter(auth=t.OAuth(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET)) 
    authkey.statuses.update(status) 

.... 

price = 99.99 
status = "buy price is $" + str(price) 
tweet(status) 

誤差即將象下面這樣:

Traceback (most recent call last): 
    File "/home/tanmaya/Documents/prog/py_prog/progs/getprice.py", line 42, in <module> 
    tweet(status) 
    File "/home/tanmaya/Documents/prog/py_prog/progs/getprice.py", line 17, in tweet 
    authkey.statuses.update(status) 
TypeError: __call__() takes 1 positional argument but 2 were given 

行號可以是不同的。我對Python的這些Web模塊和程序稍微陌生。請幫忙 !!

請注意:我使用python 3.3,所以我從python3.3軟件包頁面獲得了這個(twitter-1.9.0)。我的完整程序有點長,所以我不想移動到其他版本的Python。

回答

1

根據您發佈的包的樣品使用,您應該使用以下語法您def tweet(status):

authkey.statuses.update(status=status) 

注意內使用status=status的...使用關鍵字參數,而不是位置參數

爲了澄清,你的代碼做全髖關節置換後成爲

def tweet(status): 
    if len(status) > 140 : 
     raise Exception ('Status message too long !!!') 
    authkey = t.Twitter(auth=t.OAuth(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET)) 
    authkey.statuses.update(status=status) # <----- only this line changes 

.... 

price = 99.99 
status = "buy price is $" + str(price) 
tweet(status) 
+0

ti得到了下面的錯誤\ n追蹤(最近呼叫最後): 文件「/home/tanmaya/Documents/prog/py_prog/progs/getprice.py」,第41行,在 tweet(status = status1) TypeError :tweet()得到了一個意想不到的關鍵字參數'狀態' –

+0

錯誤 - 你是否改變了'tweet'函數'def tweet(status = status)'?不要這麼做 - 改變我在**你的'tweet'函數內指出的** –

+0

否我已經改變了你告訴的位置。\ n def tweet(status1):\ n \ tif len(狀態) > 140:\ n \ traise異常('狀態信息太長!!!')\ n authkey = t.Twitter(auth = t.OAuth(ACCESS_TOKEN_KEY,ACCESS_TOKEN_SECRET,CONSUMER_KEY,CONSUMER_SECRET))\ n authkey.statuses .update(status = status1)\ n \ n price = 99.99 \ n status1 =「buy price is $」+ str(price)\ n tweet(status = status1) –