Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instabot KeyError: 'urlgen'

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'
like image 532
Ulises Millán Avatar asked Feb 01 '21 22:02

Ulises Millán


3 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.

like image 99
Raj Kalathiya Avatar answered Sep 24 '22 20:09

Raj Kalathiya


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)
like image 39
Uros Pocek Avatar answered Sep 24 '22 20:09

Uros Pocek


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

like image 29
Julian Avatar answered Sep 24 '22 20:09

Julian