我使用的是Python 2.7.15,我正在尝试创建一个GUI,该GUI将允许您使用自定义源标签(“ Twitter for ...”)进行鸣叫,但是在接受源标签变量的情况下,当前代码确实可以不喜欢将状态作为变量。
代码:
import tweepy
from Tkinter import *
auth = tweepy.OAuthHandler('lol', 'nice')
auth.set_access_token('try', 'xD')
api = tweepy.API(auth)
def tweet():
message = messageStorage.get()
sourceLabel = sourceLabelStorage.get()
api.update_status(message, source = sourceLabel)
gui = Tk()
gui.title('')
messageStorage = StringVar()
sourceLabelStorage = StringVar()
label0 = Label(gui, text='Enter Tweet').pack()
entry0 = Entry(gui, textvariable=messageStorage).pack()
label1 = Label(gui, text='Enter Source Label').pack()
entry1 = Entry(gui, textvariable=sourceLabelStorage).pack()
button0 = Button(gui, text='Tweet', command=tweet(), bg='#1da1f2').pack(pady=5)
gui.mainloop()
错误:
Traceback (most recent call last):
File "C:/Users/My Name/Desktop/customSourceLabel_twitter.py", line 24, in <module>
button0 = Button(gui, text='Tweet', command=tweet(), bg='#1da1f2').pack(pady=5)
File "C:/Users/My Name/Desktop/customSourceLabel_twitter.py", line 12, in tweet
api.update_status(message, source = sourceLabel)
File "C:\Python27\lib\site-packages\tweepy\api.py", line 195, in update_status
)(post_data=post_data, *args, **kwargs)
File "C:\Python27\lib\site-packages\tweepy\binder.py", line 250, in _call
return method.execute()
File "C:\Python27\lib\site-packages\tweepy\binder.py", line 234, in execute
raise TweepError(error_msg, resp, api_code=api_error_code)
TweepError: [{u'message': u'Missing required parameter: status.', u'code': 170}]
预先感谢
答案 0 :(得分:0)
在the Tweepy documentation中,似乎必须将第一个参数明确标识为status
,如下所示:
api.update_status(status=message, source=sourceLabel)
编辑:正如@Bryan Oakley指出的那样,您的代码中还有一个另一个错误-在调用Button()
(参数{{ 1}}的函数名称后不应带有括号-但这与您所发布的错误消息是分开的,并且除此以外。