【发布时间】:2015-04-03 11:56:50
【问题描述】:
所以我正在尝试使用 tweepy 发送带有变量的推文。准确的说,整条推文都是一个变量。
代码sn-p:
tweet = '"If you don\'t think every day is a good day, just try missing one." - Cavett Robert\n\n Tweet URL: https://twitter.com/\nhttp://redd.it/31a5k0'
status = api.update_status(status=tweet)
当我运行它时,我得到了这个错误:
Traceback (most recent call last):
File "<pyshell#76>", line 1, in <module>
api.update_status(status=tweet)
File "C:\Python34\lib\site-packages\tweepy\api.py", line 193, in update_status
)(post_data=post_data, *args, **kwargs)
File "C:\Python34\lib\site-packages\tweepy\binder.py", line 239, in _call
return method.execute()
File "C:\Python34\lib\site-packages\tweepy\binder.py", line 223, in execute
raise TweepError(error_msg, resp)
tweepy.error.TweepError: Twitter error response: status code = 403
这不是因为推文太长。它是 139 个字符。
当我使用api.update_status(status='Hello') 时,它完全可以正常工作。只有当我使用它破坏的变量时。
我还尝试了以下方法:api.update_status(status='%s' % tweet)api.update_status(status=('%s' % tweet))api.update_status(status='{0}'.format(tweet))api.update_status(status=str(tweet))
现在我是 python 新手,所以我不完全理解错误。有人可以告诉我为什么这不起作用以及如何正确使用它吗?
【问题讨论】:
-
你是如何对 twitter 进行身份验证的?您的 API 密钥有效吗?
-
是的@ThomWiggers。我确实说过当我不使用变量时它可以正常工作。
标签: python python-3.x twitter tweepy