Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix api.py according to new Instagram API format #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

energizer91
Copy link

Currently Instagram returns csrf_token inside nested object called config. These changes fix it.

Currently Instagram returns `csrf_token` inside nested object called `config`. These changes fix it.
@BeatrixKiddo3000
Copy link

Hi,
I have the same problem with windows10.
Could not login: Expecting value: line 1 column 1 (char 0)
How can I fix it?
How I can update api.py?
Can you guide me? Thanx for help!

@energizer91
Copy link
Author

hi @BeatrixKiddo3000, just recreate changes i've made in this PR on your local files and you're good to go

@Eikreis
Copy link

Eikreis commented Nov 4, 2022

I tried making these changes and it now returns a different error.

[E] Could not login: HTTPSConnectionPool(host='www.instagram.com', port=443): Read timed out. (read timeout=5)

If I use an old login session, it gets past this and goes into the error mentioned in another thread:

[E] Could not get livestream information: Expecting value: line 1 column 1 (char 0)

@F1atCat
Copy link

F1atCat commented Nov 4, 2022

Hi,
I have the same problem with windows10.
Could not login: Expecting value: line 1 column 1 (char 0)
How can I fix it?
How I can update api.py?
Can you guide me? Thanx for help!

You can install it by using the commit code, like so:

pip install git+https://github.com/dvingerh/PyInstaLive.git@0c6c53161efda1c3a96787206544015a81ee159c

@BeatrixKiddo3000
Copy link

You can install it by using the commit code, like so:

pip install git+https://github.com/dvingerh/PyInstaLive.git@0c6c53161efda1c3a96787206544015a81ee159c

Don't work, same error:
[E] Could not login: Expecting value: line 1 column 1 (char 0)

What can I do?

@nimrahwt
Copy link

nimrahwt commented Nov 5, 2022

You can install it by using the commit code, like so:

pip install git+https://github.com/dvingerh/PyInstaLive.git@0c6c53161efda1c3a96787206544015a81ee159c

Don't work, same error: [E] Could not login: Expecting value: line 1 column 1 (char 0)

What can I do?

yes, it didn't work, the file in the folder wasn't updated
do it manually:

download the raw directly from
https://github.com/dvingerh/PyInstaLive/blob/0c6c53161efda1c3a96787206544015a81ee159c/pyinstalive/api.py
and replace it with the api.py in this folder
C:\Users\username\AppData\Local\Programs\Python\Python39\Lib\site-packages\pyinstalive

then it works

but now I have this error
[I] Successfully created a new login session file: xxx.dat
[E] Could not login: "name='csrftoken', domain=None, path=None"
...
[I] An existing login session file was found: xxx.dat
[I] Checking the validity of the saved login session.
[E] Could not login: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

I've downgraded to version 3.24 and updated the .ini file, now I can login and hopefully record the next stream when it starts
pip install git+https://github.com/notcammy/PyInstaLive.git@3.2.4 --upgrade
https://github.com/dvingerh/PyInstaLive/blob/3.2.4/README.md

@Eikreis
Copy link

Eikreis commented Nov 6, 2022

Downgrading to 3.2.4 appears to have worked. Much appreciated!

@BeatrixKiddo3000
Copy link

BeatrixKiddo3000 commented Nov 7, 2022

work me too downgrading to 3.2.4 version with old .ini file

but after only 3 hours give me this error:
"Could not finish checking following users: Unauthorized: Please wait a few minutes before you try again"

If i delete cookie work for 3 hours and then the same error....

@fireattack
Copy link

This PR still does not work here:

G:\_temp\instalive\PyInstaLive>python -m pyinstalive -d daaai_chan
---------------------------------------------------------------------------
[I] PYINSTALIVE (SCRIPT V4.0.2 - PYTHON V3.11.1) - 12-24-2022 06:18:46 PM
---------------------------------------------------------------------------
[I] An existing login session file was found: ***.dat
[I] Checking the validity of the saved login session.
---------------------------------------------------------------------------
[I] Successfully logged in using account: ***
[I] The login session file will expire on: 07-15-2023 at 12:05:15 PM
---------------------------------------------------------------------------
[I] Getting livestream information for user: daaai_chan
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "G:\_temp\instalive\PyInstaLive\pyinstalive\__main__.py", line 9, in <module>
    run()
  File "G:\_temp\instalive\PyInstaLive\pyinstalive\startup.py", line 168, in run
    globals.download.start()
  File "G:\_temp\instalive\PyInstaLive\pyinstalive\download.py", line 40, in start
    user_info = api.get_user_info().get("data", {}).get("user", None)
                ^^^^^^^^^^^^^^^^^^^
  File "G:\_temp\instalive\PyInstaLive\pyinstalive\api.py", line 29, in get_user_info
    return json.loads(response.text) if response.status_code == 200 else {}
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\***\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\***\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\***\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

It's trying to fetch https://i.instagram.com/api/v1/users/web_profile_info/?username={username} but the response is HTML, not JSON

@hedgerow512
Copy link

hedgerow512 commented Dec 7, 2023

work me too downgrading to 3.2.4 version with old .ini file

but after only 3 hours give me this error: "Could not finish checking following users: Unauthorized: Please wait a few minutes before you try again"

If i delete cookie work for 3 hours and then the same error....

I made a python script to delete your cookies automatically:

import os
import time

username = "your_instagram_username"
cookie_dir = "/path/to/pyinstalive/"
times_run = 0

print("Automatic Cookie Deleter for pyinstalive")
hours = input("Choose hourly interval: ")

while True:
    print("Deleting cookies every " + hours + " hour(s)")
    time.sleep(3600 * float(hours))
    os.system("rm '" + cookie_dir + username + ".json'")
    times_run = times_run + 1
    print("Cookies deleted a total of " + str(times_run) + " time(s)")

Make sure you change the username = and cookie_dir = values to match your username as well as your pyinstalive location.

Run this in another terminal window. If you're using Windows, I think you might have to replace rm with del in os.system(), but otherwise the command should work across Unix-like systems (such as Mac and Linux).

When you run the program, it will ask you how often you'd like for the cookies to be deleted in hours. Decimal points work too! Press enter, and the program will continue to run until you decide to close it.

@Milor123
Copy link

I made a python script to delete your cookies automatically:

Could you do a script that allow use my chrome cookies as .dat file for this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants