0

I have the following in a script:

import requests
from json import loads

s = requests.Session()                                                                                                                                                                                            
r = s.get("https://iforgot.apple.com/password/verify/appleid", headers=headers)                                                                                                                                   
headers['Sstt'] = loads([line for line in r.text.split("\n") if "sstt" in line][0])["sstt"]                                                                                                                       
headers['Content-Type'] = "application/json"                                                                                                                                                                      
data = f'{{"id":"{email}"}}'                                                                                                                                                                                      
r = s.post("https://iforgot.apple.com/password/verify/appleid", data=data, headers=headers, allow_redirects=False).headers['Location']                                                                            
headers['Accept'] = 'application/json, text/javascript, */*; q=0.01'                                                                                                                                              
r = s.get(f"https://iforgot.apple.com{r}", headers=headers, allow_redirects=False).json()['trustedPhones'][0]                                                                                                     
c = r['countryCode']                                                                                                                                                                                              
n = r['numberWithDialCode'] 

Whenever I run this, I receive this error:

File "/home/user/xsint/modules/apple.py", line 10, in apple                                              
    headers['Sstt'] = loads([line for line in r.text.split("\n") if "sstt" in line][0])["sstt"]
File "/usr/lib/python3.7/json/__init__.py", line 348, in loads                                           
    return _default_decoder.decode(s)                                                                    
File "/usr/lib/python3.7/json/decoder.py", line 340, in decode                                           
    raise JSONDecodeError("Extra data", s, end)                                              
json.decoder.JSONDecodeError: Extra data: line 1 column 10 (char 9)

But the thing that I really can't figure out is if I run each of these commands in a Python 3 console they work. Does anyone see what the problem is?

unkn0wn.dev
  • 235
  • 2
  • 8

2 Answers2

1

First, I think line 10 and 12 is incomplete?

LINE 10 : data, headers=headers, all$
LINE 12 : json()['trus$

Second, it will be more helpful with more error message.

Joo Hyuk Kim
  • 68
  • 1
  • 5
1

[EDITED]

You have more than one data in your json, and json.loads() is not able to decode more than one.

check below line

headers['Sstt'] = loads([line for line in r.text.split("\n") if "sstt" in line][0])["sstt"]                                                                                                                       

it must be not a json format change to something like

{
    "key" :[value, value]
  }

and it should work,

Python json.loads shows ValueError: Extra data

Joo Hyuk Kim
  • 68
  • 1
  • 5