subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.38k stars 685 forks source link

[BUG]Login /Challenge required #1479

Closed NicoRulli closed 1 year ago

NicoRulli commented 1 year ago

I have been trying for ages now to get my code to work without login issues. I just used the suggested function and session.JSON file. My account is now saying challenge)_required

I even gave it the 6 digit code sent to my email and this is the traceback: Traceback (most recent call last): File "/Users/Shared/InstagramAutomated/file2.py", line 67, in login_user() File "/Users/Shared/InstagramAutomated/file2.py", line 64, in login_user raise Exception("Couldn't login user with either password or session") Exception: Couldn't login user with either password or session

@adw0rd can you please help with this?

logger = logging.getLogger()

def login_user(): """ Attempts to login to Instagram using either the provided session information or the provided username and password. """

cl = Client()
session = cl.load_settings("session.json")

login_via_session = False
login_via_pw = False

if session:
    try:
        cl.set_settings(session)
        cl.login(USERNAME, PASSWORD)

        # check if session is valid
        try:
            cl.get_timeline_feed()
        except LoginRequired:
            logger.info("Session is invalid, need to login via username and password")

            old_session = cl.get_settings()

            # use the same device uuids across logins
            cl.set_settings({})
            cl.set_uuids(old_session["uuids"])

            cl.login(USERNAME, PASSWORD)
        login_via_session = True
    except Exception as e:
        logger.info("Couldn't login user using session information: %s" % e)

if not login_via_session:
    try:
        logger.info("Attempting to login via username and password. username: %s" % USERNAME)
        if cl.login(USERNAME, PASSWORD):
            login_via_pw = True
    except Exception as e:
        logger.info("Couldn't login user using username and password: %s" % e)

if not login_via_pw and not login_via_session:
    raise Exception("Couldn't login user with either password or session")

login_user()

above is my code.

I now have to wait for this challenge required issue to be resolved.

adw0rd commented 1 year ago

Do you think this is an Instagrapi bug? Why?

I still do not understand your problem, did you have a challenge? So solve it

You show what exceptions that you yourself created, I absolutely do not understand anything, what is your problem?

NicoRulli commented 1 year ago

I solved the challenge and so far it seems to be working. As I've said a few times before, I am new to github. There is only a place to add 'bugs' but to my knowledge there isn't a place to ask questions. therefore bugs is the only area I can voice my issues.

My current bug is 'clipNotUpload' which is coming from the clips.py file I believe. line 144. I made a post about that.

adw0rd commented 1 year ago

place to ask questions

https://github.com/adw0rd/instagrapi/discussions