0

twitter-1.9.0(http://pypi.python.org/pypi/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

行番号は異なる場合があります。私はこれらのWebモジュールとPythonのプログラムに少し慣れていません。助けてください !!

注意:私はpython 3.3を使用しているので、python3.3パッケージページからこれだけ(twitter-1.9.0)を入手しました。私の完全なプログラムは少し長いので、他のバージョンのpythonに移行したくありません。

4

1 に答える 1

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)
于 2012-12-12T19:50:51.027 に答える