0

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.

Tanmaya Meher
  • 1,438
  • 2
  • 16
  • 27

1 Answers1

1

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)
Jon Clements
  • 138,671
  • 33
  • 247
  • 280
  • after doing that i got the below error\n Traceback (most recent call last): File "/home/tanmaya/Documents/prog/py_prog/progs/getprice.py", line 41, in tweet(status=status1) TypeError: tweet() got an unexpected keyword argument 'status' – Tanmaya Meher Dec 12 '12 at 19:56
  • Err - have you changed your `tweet` function `def tweet(status=status)`? Don't do that - change the line I pointed out **inside** your `tweet` function – Jon Clements Dec 12 '12 at 20:06
  • No I have changed at the position you told.\n def tweet(status1):\n \tif len(status) > 140 :\n \traise Exception ('Status message too long !!!')\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) – Tanmaya Meher Dec 12 '12 at 20:10
  • 1
    @tanmay updated post to make it more explicit on what needs changing - your `tweet` function definition and call don't need changing – Jon Clements Dec 12 '12 at 20:13
  • Thanks a ton for your help at 1:50 AM (night here :-) ) – Tanmaya Meher Dec 12 '12 at 20:21
  • just for knowledge sake would you explain me why that was happening (I am not able to understand, why we need to write that exact things "status keyword" , but in some other python defined functions, we donot have to ?!! – Tanmaya Meher Dec 12 '12 at 20:24
  • It's the way the library you're using has been written to work (because of the way it chooses to work with twitter) - if you look at the most of the commands it provides, they're mostly keyword arguments because it uses attribute access to mimic the URL structure of twitter requests and your keyword arguments become parameters to the URL. Python isn't like that in general - I would just bear it in mind using this library though :) – Jon Clements Dec 12 '12 at 20:28
  • thanks, a lot. even in the site of the python3.3 module twitter 1.9.0, the last program is error prone (this error !!). – Tanmaya Meher Dec 12 '12 at 20:50