tensojka / instastories-backup

Backup your friends' Instagram Stories forever and get to keep them even after 24 hours.
MIT License
85 stars 20 forks source link

KeyError: 'items' #4

Closed Retul15 closed 6 years ago

Retul15 commented 6 years ago

It worked few months well but now I'm getting this error. I have changed my Instagram cookies to a different account but still getting this error. Loading new entries to DB Traceback (most recent call last): File "main.py", line 26, in <module> for item in response['items']: KeyError: 'items'

tensojka commented 6 years ago

I'm sorry but I won't be able to help you until the week after the next week, because I won't have access to my development machine until then.

ne 4. 2. 2018 v 19:25 odesílatel Retul15 notifications@github.com napsal:

It worked few months well but now I'm getting this error. I have changed my Instagram cookies to a different account but still getting this error. Loading new entries to DB Traceback (most recent call last): File "main.py", line 26, in for item in response['items']: KeyError: 'items'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hoschiCZ/instastories-backup/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/AIE_Sgv1sTXCz-Vin6z8GXjbSHTnIrSTks5tRfYmgaJpZM4R4qn0 .

tensojka commented 6 years ago

Can you please add this on line 25 in main.py? print(response) Then tell me what error are you getting.

Retul15 commented 6 years ago

Traceback (most recent call last): File "main.py", line 9, in prefs = json.load(json_data) File "/usr/lib/python3.5/json/init.py", line 268, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "/usr/lib/python3.5/json/init.py", line 319, in loads return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting ',' delimiter: line 9 column 681 (char 842)

tensojka commented 6 years ago

This seems to be a different error from the last one, this time the script doesn't even get to line 25. Looks like your prefs.json is invalid. You can run it through an online JSON validator to check what's the problem.

Retul15 commented 6 years ago

I'm getting this error in json validator on cookie's line Error: Parse error on line 9: ...249233%7D; urlgen=" {\ "time\": 15177 -----------------------^ Expecting 'EOF', '}', ':', ',', ']', got '{'

But I'm sure I copy pasted the right Instagram cookies as before.

tensojka commented 6 years ago

Yes, you pasted the right Instagram cookies. Instagram changed their cookies format and now they include the character " in it. However, " is used as a separator in the JSON format. Every " in the cookie has to be escaped like this: \". This should solve the JSONDecodeError.

DrSchteeven commented 6 years ago

I was having the same problem. I've tried setting up a new cookie -with the escaping - but it still gave the same error. I've added the print(response) under the line 25. It prints the whole data like: {'expiring_at': 1519667880, 'seen': 0.0, ....... 'latest_reel_media': None} and after doing this for each account it prints out

ERROR: got 400 when fetching stories entries!
{'status': 'fail', 'message': 'Invalid target user.'}
Traceback (most recent call last):
  File "main.py", line 27, in <module>
    for item in response['items']:
KeyError: 'items'

I got a suspect and checked each account, it seems like one of them got deleted/deactivated by the user. I've deleted the user id from the prefs.json and it worked again as usual.

It seems like the script crashes with that error if there is only one user id that doesn't work. Maybe it could be made to just print an error with the name and userid and proceed to the next user?

tensojka commented 6 years ago

Great idea @DrSchteeven ! I will implement this!