无法使用python3.3及其包twitter-1.9.0向twitter发送状态消息
使用twitter-1.9.0() 我正在尝试发送状态消息,但无法发送。下面是代码片段无法使用python3.3及其包twitter-1.9.0向twitter发送状态消息,python,python-3.x,python-3.3,Python,Python 3.x,Python 3.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.Twi
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
回溯(最近一次呼叫最后一次):
文件“/home/tanmaya/Documents/prog/py_prog/progs/getprice.py”,第42行,在
推特(状态)
文件“/home/tanmaya/Documents/prog/py_prog/progs/getprice.py”,第17行,在tweet中
authkey.status.update(状态)
TypeError:\uuuu call\uuuu()接受1个位置参数,但提供了2个
行号可能不同。我对python的这些web模块和程序有点陌生。请帮忙
请注意:我使用的是python3.3,所以我只从python3.3包页面获得了这一个(twitter-1.9.0)。我的完整程序有点长,所以我不想转到其他版本的python 根据您发布的包的示例用法,您应该在
def tweet(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)
def tweet(状态):
如果len(状态)>140:
引发异常('状态消息太长!!!')
authkey=t.Twitter(auth=t.OAuth(ACCESS\u-TOKEN\u-KEY,ACCESS\u-TOKEN\u-SECRET,CONSUMER\u-KEY,CONSUMER\u-SECRET))
authkey.statuses.update(status=status)#执行此操作后,我得到了以下错误\n回溯(最近一次调用):文件“/home/tanmaya/Documents/prog/py_prog/progs/getprice.py”,第41行,在tweet(status=status1)类型错误:tweet()出现意外的关键字参数“status”错误-您是否更改了tweet
函数def tweet(status=status)
?不要这样做-更改我在您的tweet
函数中指出的行我在您告诉的位置没有更改。\n def tweet(状态1):\n\tif len(状态)>140:\n\traise Exception('状态消息太长!!!')\n authkey=t.Twitter(auth=t.OAuth(ACCESS\u TOKEN\u KEY、ACCESS\u TOKEN\u SECRET、CONSUMER\u KEY、CONSUMER\u SECRET))\n authkey.statuses.update(status=status1)\n\n price=99.99\n status1=“购买价格为$”+str(价格)\n tweet(status=status1)@tanmay更新了帖子,使其更明确地说明了需要更改的内容-您的tweet
函数定义和调用不需要更改感谢您在凌晨1:50的帮助(这里的夜晚:-)
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)