属性错误:"API"对象没有属性"会话"



Using Version: 0.117.0 of instabot.

已经登录,我运行:

from instabot import Bot
insta = Bot()
insta.upload_photo(photo_path,caption ="just try")

这是我得到的:

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'

您可以在login()方法中指定use_cookie参数为False,这意味着bot将使用cookie而不是每次需要推送一些请求时重新登录。默认为True

bot.login(username="",password="",use_cookie=False)

我已经运行login之前,它应该存储凭据。当我重新登录时,它总是给我:

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'

我以为这是你已经登录时的反馈。我仍然不确定为什么我的第一次登录似乎失败。以及为什么它不能给出适当的反馈。在dezese的回答之后,我开始怀疑登录是否成功,我发现了这个我只是结束运行:

rm -rf config

然后代码正确login:

insta = Bot()
insta.login(username=username,password=password)
insta.upload_photo(photo_path,caption ="just try")

一切都成功了!谢谢你给我指了正确的方向。我希望这个详细的解释能帮助到有类似问题的人,因为那些错误代码对找到真正的原因并没有真正的帮助。

目前我必须删除配置文件夹每次。不是最好的解决方案,但目前可行。如果有人知道更好的方法,请贴出来,我会接受答案

我通过在bot.login()之前删除uuid_and_cookie.json来解决这个问题

import os
try:
os.remove("config/<your_username>_uuid_and_cookie.json")
except:
pass

当文件存在时有一个错误

相关内容

  • 没有找到相关文章

最新更新