キーを使用してエンティティを更新したいのですが、何か問題があります。ここに私のコード:
def post(self):
username = self.request.get("contentb")
header, response = client.request('https://api.twitter.com/1.1/followers/ids.json?cursor=-1&screen_name='+username+'&count=5000')
ids = [str(id) for id in json.loads(response)["ids"]]
messages = []
userlist = [user.username for user in User.query().fetch(projection=["username"])]
if username not in userlist:
user = User()
user.username = username
user.follower_list = ids
key = user.put()
messages.append("Ok we added you")
else:
followerlist = [user.follower_list[0] for user in User.query().filter(User.username == username).fetch(projection=["follower_list"])]
if len(set(followerlist)-set(ids)) == 0:
messages.append("No one has unfollowed you :)")
else:
for i in set(followerlist)-set(ids):
messages.append(str(i) + " " + "unfollowed you")
user = key.get()
user.follower_list = ids
user.put()
messages.append("We updated your followerlist")
しかし、私はエラーが発生します:
user = key.get()
UnboundLocalError: local variable 'key' referenced before assignment
どこが間違っているか教えてください。