【问题标题】:How to fix "NameError: name 'api' is not defined" Tweepy.py如何修复 \"NameError: name \'api\' is not defined\" Tweepy.py
【发布时间】:2022-11-23 05:35:08
【问题描述】:

错误 ”

Traceback (most recent call last):
  File "/home/dcaus/tweet-custom-label.py", line 16, in <module>
    api.update_with_media(filename, status, in_reply_to_status_id = in_reply_to_status_id)
NameError: name 'api' is not defined

“ 我的代码

import tweepy

# Authenticate to Twitter
auth = tweepy.OAuthHandler("Token Is Hidden For Privacy.", "Token Is Hidden For Privacy.")
auth.set_access_token("Token Is Hidden For Privacy.", "Token Is Hidden For Privacy.")

# Create API object
status = "This is cool"

in_reply_to_status_id = "1595131614425542656"
filename = "Property 1=Default.png"
api.update_with_media(filename, status, in_reply_to_status_id = in_reply_to_status_id)

【问题讨论】:

  • 您永远不会创建 api 对象。

标签: python tweepy


【解决方案1】:

设置身份验证后,您需要创建一个 API 对象。你错过了类似的东西

api = tweepy.API(auth, wait_on_rate_limit=True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 2022-12-02
    • 2013-04-09
    • 2020-09-06
    • 2020-11-07
    • 2017-01-09
    相关资源
    最近更新 更多