Question

Using the twitter-1.9.0 (http://pypi.python.org/pypi/twitter/1.9.0) I am trying to send a status message but unable to do it. below is the code snippet.

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)

error is coming like below:

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

Line number may be different. I am slightly new to these web modules and programs of python. please help !!

please note : i am using python 3.3 so I got this one only (twitter-1.9.0), from the python3.3 package pages. my complete program is a bit longer, so i donot want to move to other version of python.

Was it helpful?

Solution

According to the sample usage of the package you posted, you should be using the following syntax inside your def tweet(status):

authkey.statuses.update(status=status)

Note the use of the status=status... to use a keyword argument, rather than a positional parameter

To clarify, your code becomes

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top