这个问题在这里已有答案:
我使用Python 2.7.15并且我正在尝试创建一个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}]
提前致谢
从the Tweepy documentation,看起来你必须明确地将第一个参数识别为status
,如下所示:
api.update_status(status=message, source=sourceLabel)
编辑:正如@Bryan Oakley指出的那样,你的代码中还有另一个错误 - 在你调用Button()
时,参数command=tweet
在函数名后面不应该有括号 - 但是它与错误消息分开并且除了错误消息之外你发布了。