因此,我尝试使用tweepy发送带有变量的推文。确切地说,整个推文是一个变量。
程式码片段:
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打包链接(https://dev.twitter.com/overview/t.co)之后,带有两个链接的长推文实际上超过140个字符。每个链接最终为22个字符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句