Reputation: 979
Using Version: 0.117.0 of instabot.
Already being logged in I run:
from instabot import Bot
insta = Bot()
insta.upload_photo(photo_path,caption ="just try")
This is what I get:
2021-02-11 00:38:56,519 - INFO - Instabot version: 0.117.0 Started
FOUND: w:1024 h:1024 r:1.0
Traceback (most recent call last):
File "main.py", line 43, in <module>
insta.upload_photo(photo_path,caption ="just try")
File "/Users/user/.virtualenvs/v3/lib/python3.8/site-packages/instabot/bot/bot.py", line 806, in upload_photo
return upload_photo(self, photo, caption, upload_id, from_video, options)
File "/Users/user/.virtualenvs/v3/lib/python3.8/site-packages/instabot/bot/bot_photo.py", line 26, in upload_photo
result = self.api.upload_photo(
File "/Users/user/.virtualenvs/v3/lib/python3.8/site-packages/instabot/api/api.py", line 825, in upload_photo
return upload_photo(
File "/Users/user/.virtualenvs/v3/lib/python3.8/site-packages/instabot/api/api_photo.py", line 154, in upload_photo
self.session.headers.update(
AttributeError: 'API' object has no attribute 'session'
Upvotes: 0
Views: 2132
Reputation: 36
you can specify use_cookie
parameter as False
in login()
method which means that bot would use cookies not to re-login every time it needs to push some request. Defaults as True
.
bot.login(username="",password="",use_cookie=False)
Upvotes: 2
Reputation: 1
I solved it by just deleting the uuid_and_cookie.json
before bot.login()
import os
try:
os.remove("config/<your_username>_uuid_and_cookie.json")
except:
pass
There's a bug when the file exists
Upvotes: 0
Reputation: 979
I already ran login before and it is supposed to store the credentials. When I reran login it always gave me:
2021-02-11 07:20:42,052 - INFO - Instabot version: 0.117.0 Started
Traceback (most recent call last):
File "main.py", line 42, in <module>
insta.login(username=username,password=password)
File "/Users/user/.virtualenvs/v3/lib/python3.8/site-packages/instabot/bot/bot.py", line 443, in login
if self.api.login(**args) is False:
File "/Users/user/.virtualenvs/v3/lib/python3.8/site-packages/instabot/api/api.py", line 240, in login
self.load_uuid_and_cookie(load_cookie=use_cookie, load_uuid=use_uuid)
File "/Users/user/.virtualenvs/v3/lib/python3.8/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 "/Users/user/.virtualenvs/v3/lib/python3.8/site-packages/instabot/api/api_login.py", line 354, in load_uuid_and_cookie
self.cookie_dict["urlgen"]
KeyError: 'urlgen'
Which I thought was the feedback when you are already being logged in. I am still not sure why my first login seemed to fail. And why it doesn't give a proper feedback. After dezese's answer I started doubting that the login was successful and I found this I just ended up running:
rm -rf config
And then the code properly with login:
insta = Bot()
insta.login(username=username,password=password)
insta.upload_photo(photo_path,caption ="just try")
And everything worked! Thanks deceze for pointing me in the right direction. I hope this detailed explanation helps people with similar issues, since those error codes are not really helpful in finding the true cause.
Currently I have to delete the config folder every time. Not the best solution but works for now. If anybody knows a better way please post it and I will accept the answer
Upvotes: 1