【问题标题】:Twitter Error Code 400 when tweeting an emoji推特表情符号时出现推特错误代码 400
【发布时间】:2016-01-11 20:41:43
【问题描述】:

我知道我的身份验证工作正常,我可以正常发布推文。我没有理由相信 tweepy 库导致了这个问题,尽管我想我没有理由排除它。我的代码看起来像这样,试图在推特上发布一个表情符号。也没有其他表情符号在起作用。

auth = tweepy.OAuthHandler(keys.twitter['consumer_key'], keys.twitter['consumer_secret'])
auth.set_access_token(keys.twitter['access_token'], keys.twitter['access_token_secret'])
api = tweepy.API(auth)
print('Connected to the Twitter API...')
api.update_status(r'testing \U0001F1EB\U0001F1F7')

我收到了error code 400,似乎没有关于原因的其他信息。试图确定问题是否是字符串中的编码有某种错误,或者只是将它发送到 Twitter 的 API 的某种问题。

【问题讨论】:

    标签: python-3.x twitter


    【解决方案1】:

    您的字符串中有 unicode。因为您使用的是 Python 2,所以使用:

    api.update_status(u"testing \U0001F1EB\U0001F1F7")
    

    请注意,我将 r"x" 更改为 u"x"。

    如果您使用的是 Python 3,则可以使用:

    api.update_status("testing \U0001F1EB\U0001F1F7")
    

    更新:这是我使用此代码发送的推文:

    https://twitter.com/twistedhardware/status/686527722634383360

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 2013-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多