首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >字符串变量在带有源标签的api.update_status中作为状态

字符串变量在带有源标签的api.update_status中作为状态
EN

Stack Overflow用户
提问于 2019-03-05 20:35:55
回答 1查看 467关注 0票数 0

我使用Python2.7.15,我正在尝试创建一个GUI,它允许您使用自定义的源标签("Twitter .“)但是我的当前代码在接受变量作为源标签时,它不喜欢将状态作为变量。

代码:

代码语言:javascript
运行
复制
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()

错误:

代码语言:javascript
运行
复制
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}]

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-05 20:46:23

Tweepy文献中,您似乎必须将第一个参数显式地标识为status,如下所示:

代码语言:javascript
运行
复制
api.update_status(status=message, source=sourceLabel)

编辑:正如@Bryan所指出的那样,在代码中还有另一个bug --在调用Button()时,参数command=tweet不应该在函数名后面加上括号--但是这与您发布的错误消息是分开的,而且除了您发布的错误消息之外。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55011160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档