简体   繁体   English

Instabot API for Python 在第二次运行代码后引发错误

[英]Instabot API for Python raises error after running code for the 2nd time

I am currently working with the Instabot API for python and I ran across the following issue:我目前正在使用 Instabot API for python 并且遇到以下问题:

I wrote a small program:我写了一个小程序:

from instabot import Bot

bot = Bot()
bot.login(username = "[my username]", password = "[my passowrd]")

bot.follow("lego")

which worked fine after running it for the very first time.第一次运行后效果很好。 However, after running the program for a second time, this time following another account, it raised an error ("KeyError: ds_user").但是,在第二次运行该程序后,这一次跟随另一个帐户,它引发了错误(“KeyError:ds_user”)。

This error can be fixed by deleting the config folder inside the project folder.可以通过删除项目文件夹中的配置文件夹来修复此错误。 Unfortunately, this isn't a very sustainable solution, as it makes working on the code really arduous.不幸的是,这不是一个非常可持续的解决方案,因为它使代码工作变得非常艰巨。 I therefore would like to know if there is any solution for getting the program to run multiple times without having to delete the config folder over and over again.因此,我想知道是否有任何解决方案可以让程序多次运行而不必一遍又一遍地删除配置文件夹。

I am receiving the following traceback (code is running in an anaconda environment called "Instagram Automation"):我收到以下回溯(代码在名为“Instagram 自动化”的 anaconda 环境中运行):

Traceback (most recent call last):
  File "e:/Programme/OneDrive/Dokumente/Projekte/Instagram Automation/main.py", line 4, in <module>
    bot.login(username = "[my username]", password = "[my password]")
  File "E:\Programme\Anaconda\envs\Instagram Automation\lib\site-packages\instabot\bot\bot.py", line 443, in login
    if self.api.login(**args) is False:
  File "E:\Programme\Anaconda\envs\Instagram Automation\lib\site-packages\instabot\api\api.py", line 240, in login
    self.load_uuid_and_cookie(load_cookie=use_cookie, load_uuid=use_uuid)
  File "E:\Programme\Anaconda\envs\Instagram Automation\lib\site-packages\instabot\api\api.py", line 199, in load_uuid_and_cookie
    return load_uuid_and_cookie(self, load_uuid=load_uuid, load_cookie=load_cookie)
  File "E:\Programme\Anaconda\envs\Instagram Automation\lib\site-packages\instabot\api\api_login.py", line 352, in load_uuid_and_cookie
    cookie_username = self.cookie_dict["ds_user"]
KeyError: 'ds_user'  

As far as I can see, the only way on your side to fight the symptoms is to always delete the JSON file in the config folder, eg:据我所见,您对抗症状的唯一方法是始终删除配置文件夹中的 JSON 文件,例如:

import os
if os.path.isfile("path/to/config/file.json"):
    os.remove("path/to/config/file.json")

import instabot
# rest of your code goes here

The developers of instabot should fix the source of the problem, for example by using self.cookie_dict.get("ds_user", "some default value") instead of self.cookie_dict["ds_user"] instabot的开发人员应该修复问题的根源,例如使用self.cookie_dict.get("ds_user", "some default value")而不是self.cookie_dict["ds_user"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM