![](/img/trans.png)
[英]Why can't I delete multiple tweets with this code? Python tweepy
[英]Flask & Tweepy - I can't handle the errors
当 Tweepy 出现问题时,我想打印。 当我查看 Tweepy 的文档时, try except
似乎是可能的。 但是尝试除之后,用户变量不来。 我在 user_profile_image: UnboundLocalError: local variable 'user' referenced before assignment
中收到此错误。
我怎么解决这个问题? 谢谢
@app.route("/twitter", methods=['GET', 'POST'])
def twitter():
if request.method == 'POST':
username = request.form.get('text')
auth = tweepy.OAuthHandler("myoauthhandlers")
auth.set_access_token("myaccesstokens")
api = tweepy.API(auth)
try:
user = api.get_user(username)
except tweepy.TweepError as e:
print("Error")
user_profile_image = user.profile_image_url.replace('normal', '400x400')
您需要在 try/except 块之前使用user = None
之类的语句定义user
。 在这里,它在 try/except 块的 scope 中定义,因此无法从其外部访问,因此是异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.