json.loads Jsondecodeerror

Asked

Viewed 142 times

2

The cookies posted here, there is no validity, so if you want to do evil, look for another

I have these cookies I saved using the PHP language

["fm=0","_twitter_sess=BAh7CSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCNndap5qAToMY3NyZl9p%250AZCIlMzkyNWI0OWVlNmIwN2M5MDQ3YzlhZDNkYzI0NmM5NmU6B2lkIiUwNTdh%250AYzUxZDk3NGUyNzE3Zjk1MWVhZGQ4MGM5OTkyZQ%253D%253D--288296a1b6be7e778a80e39cfbccb3004f174869","personalization_id=\"v1_xT6WU1iyhYSZyynU1oTJLw==\"","guest_id=v1%3A155743596488632801","ct0=f28684acf870e0f5a950d29b6feb6f2f","dnt=1","fm=0","ads_prefs=\"HBISAAA=\"","kdt=wdmo4K3PfBZiaRTx6fAXLqfqzNXdlpkHmyCH5FpP","remember_checked_on=1","_twitter_sess=BAh7CiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCNndap5qAToMY3NyZl9p%250AZCIlMzkyNWI0OWVlNmIwN2M5MDQ3YzlhZDNkYzI0NmM5NmU6B2lkIiUwNTdh%250AYzUxZDk3NGUyNzE3Zjk1MWVhZGQ4MGM5OTkyZToJdXNlcmwrCQDAlp7iWowP--fe26fef739a85a922df20c2c2a89f7d50b988670","twitter_id=\"u=1120370336678199296\"","authenticity_token=76521fd518bdd3bcf98e78f8409fe3853e486f31"]

Only that by using json.loads(...) in Python, he returns to me:

File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 332 (char 331)

I can’t use it json.loads(r'cookies strings'), because it’s coming from the database.

I believe that the json_decode PHP turns these json into another form, and since I’m migrating from PHP to python, I need all the cookies executable in Python, there’s some way to reverse that?

I’m almost 18 hours trying to solve and nothing.

My code at the moment you are:

from json import loads

cookies = '; '.join(str(loads(select_random.cookies)) + ';')    
follow_api = FollowApi()
follow = follow_api.follow(select_me.twitter_id, select_random.csrftoken, cookies)

Remembering that cookies come from the database.

PS: In PHP it works perfectly.

1 answer

0


From what I understand you’re trying to pass cookies to the right json.loads?

I don’t know if this solves the problem but first: loads won’t work because the cookie you quoted at the beginning of the question has no json format.

Second you will need to deal with double quotes when they appear repeatedly for example here "v1_xT6WU1iyhYSZyynU1oTJLw== "" because python will not understand this string.

Third even if the program has not run to that point you are using the str() function to convert the json itself after it has been formed which does not make much sense I believe you are trying to convert the contents of select_random.cookies to ai str to ai yes turns it into a json, then would be that way (loads(str(select_random.cookies)).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.