Instabot KeyError: 'urlgen'

Viewed 5720

im trying to do a instagram bot but i just could run the code once, and it worked fine but when i tried again it dropped me this error i wont write my user and pass in this question obviously haha

from instabot import *
session = Bot()
session.login(username = "myuser",
              password = "mypass")

and i get this error

2021-02-01 16:07:42,401 - INFO - Instabot version: 0.117.0 Started
Traceback (most recent call last):
  File "C:/Users/EQUIPO/Desktop/5 CUATRI/Phyton/Ejercicios Prueba/nsoe.py", line 3, in <module>
    session.login(username = "nota.niceplace",
  File "C:\Program Files\Python38\lib\site-packages\instabot\bot\bot.py", line 443, in login
    if self.api.login(**args) is False:
  File "C:\Program Files\Python38\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 "C:\Program Files\Python38\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 "C:\Program Files\Python38\lib\site-packages\instabot\api\api_login.py", line 354, in load_uuid_and_cookie
    self.cookie_dict["urlgen"]
KeyError: 'urlgen'
4 Answers

You need to delete config folder which is automatically created by system when you run this code first time. So you need to delete this folder every time before run your code. This config folder is in same directory where your file is saved.

I had same problem and i am able to solve by this way.

This code will fix everything automatically for you just change image name and path.

from instabot import Bot
import os
import shutil


def clean_up(i):
    dir = "config"
    remove_me = "imgs\{}.REMOVE_ME".format(i)
    # checking whether config folder exists or not
    if os.path.exists(dir):
        try:
            # removing it so we can upload new image
            shutil.rmtree(dir)
        except OSError as e:
            print("Error: %s - %s." % (e.filename, e.strerror))
    if os.path.exists(remove_me):
        src = os.path.realpath("imgs\{}".format(i))
        os.rename(remove_me, src)


def upload_post(i):
    bot = Bot()

    bot.login(username="your_username", password="your_password")
    bot.upload_photo("imgs/{}".format(i), caption="Caption for the post")


if __name__ == '__main__':
    # enter name of your image bellow
    image_name = "img.jpg"
    clean_up(image_name)
    upload_post(image_name)

As Raj said. You need to delete the config folder like this from where you ran the python script. Sorry for making a separate answer but for me it was not immediate clear where this config folder was so I thought it might help.

rm -rf config

Unfortunately the library is quite poor with their error messages

Unfortunately, it seems that instabot library's maintenance is down, don't try to run anything using that lib, won't work, and might, as commented by some users, compromise your account! sorry..

Related