diezo / Ensta

🔥 Fast & Reliable Python Package For Instagram API - 2024
https://bit.ly/ensta-discord
MIT License
371 stars 44 forks source link

'NoneType' object has no attribute 'user_id' #12

Closed Macerul closed 1 year ago

Macerul commented 1 year ago

Hi, when using host mode to go through the follower list I got this error:

error
diezo commented 1 year ago

To get the follower list, you need to pass either username or user id. If you pass username, the function will internally convert it to user id using Guest Class (as the get_followers api requires the user id and not the username).

And since Instagram has restricted your ip (i estimate), so can't use the guest class much frequently. And that's the reason when the function calls a method from the Guest Class, it returns an error.

So, the solution is to pass user id of that user instead of username to the followers() function. This way, the Host Class doens't need to convert username to user id and it eliminates the use of Guest Class.

Here's an example:

host.followers("cristiano")  # don't use username
host.followers(12345567)  # use user id

You may convert your list of usernames into a list of user ids and use that.

Please let me know if you have any further issues. Thanks

Macerul commented 1 year ago

To get the follower list, you need to pass either username or user id. If you pass username, the function will internally convert it to user id using Guest Class (as the get_followers api requires the user id and not the username).

And since Instagram has restricted your ip (i estimate), so can't use the guest class much frequently. And that's the reason when the function calls a method from the Guest Class, it returns an error.

So, the solution is to pass user id of that user instead of username to the followers() function. This way, the Host Class doens't need to convert username to user id and it eliminates the use of Guest Class.

Here's an example:

host.followers("cristiano")  # don't use username
host.followers(12345567)  # use user id

You may convert your list of usernames into a list of user ids and use that.

Please let me know if you have any further issues. Thanks

Sorry it may be a stupid question but how do I get the user id of the person whose I want to get the follower list?

diezo commented 1 year ago

As the Guest Class isn't working because of repetitive attempts, you can use the Host class to fetch the profile of individual users and access the attribute named user_id.

You may convert the entire list of usernames to userid using this code:

usernames = ["a", "b", "c"]  # your list
userids = []  # resulting list

for username in usernames:
    profile = host.profile(username)

    if profile is not None:
        userids.append(profile.user_id)
    else:
        print("Error. Maybe your id or ip is restricted.")
diezo commented 1 year ago

Also, the AutoHost class is released. It'll take username and password as arguments and the name of file (to store session data in) and will automatically preserve session for you. It'll create new sessionid on it's own when the existing one no longer works.

So you can replace the complex code you are using with a single line of code.

from ensta import AutoHost

host = AutoHost("username", "password", file="session.txt")

host.profile("cristiano")  # use as usual

NOTE: Use it as a replacement of Host Class, not along with it.

Macerul commented 1 year ago

Also, the AutoHost class is released. It'll take username and password as arguments and the name of file (to store session data in) and will automatically preserve session for you. It'll create new sessionid on it's own when the existing one no longer works.

So you can replace the complex code you are using with a single line of code.

from ensta import AutoHost

host = AutoHost("username", "password", file="session.txt")

host.profile("cristiano")  # use as usual

NOTE: Use it as a replacement of Host Class, not along with it.

Thanks! Using the user id instead of the username worked just fine.

diezo commented 1 year ago

You're welcome!

Feel free to ask any further questions you may have regarding ensta.