Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error json
#1
Greetings, in my code, I try to list only the parameters I need. In this case, they are face attributes and emotions. I still get a mistake. that string indexes must be integers


error list

return user['faceAttributes']['emotion']
TypeError: string indices must be integers

headers = {
    'Ocp-Apim-Subscription-Key': 'cccf20b44cb9445a8a4239ce324acfed',
    'Content-Type': 'application/octet-stream'
}
parameters = {
    'returnFaceId': 'true',
    'returnFaceLandmarks': 'false',
    'returnFaceAttributes': 'age,gender,emotion'
}

def post_image(img_data):
    response = requests.post(BASE_URL, params=parameters,
                             headers=headers, data=img_data)
    try:
        return response.json()
    except:
        return None

def get_emotions(jsonData):
    j = json.dumps(jsonData)
    halo = json.loads(j)
    for user in halo:
        return user['faceAttributes']['emotion']
Reply


Messages In This Thread
error json - by pifko22 - Apr-13-2019, 01:05 AM
RE: error json - by snippsat - Apr-13-2019, 01:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  json loads throwing error mpsameer 8 741 Jan-23-2024, 07:04 AM
Last Post: deanhystad
  json decoding error deneme2 10 3,737 Mar-22-2023, 10:44 PM
Last Post: deanhystad
  python requests library .JSON() error mHosseinDS86 6 3,486 Dec-19-2022, 08:28 PM
Last Post: deanhystad
  Read nested data from JSON - Getting an error marlonbown 5 1,401 Nov-23-2022, 03:51 PM
Last Post: snippsat
  JSON Decode error when using API to create dataframe Rubstiano7 4 2,977 Jan-11-2021, 07:52 PM
Last Post: buran
  Empty response to request causing .json() to error t4keheart 1 10,110 Jun-26-2020, 08:35 PM
Last Post: bowlofred
  empty json file error mcmxl22 1 10,194 Jun-17-2020, 10:20 AM
Last Post: buran
  json.dumps output error in python3 prayuktibid 2 2,684 Jan-21-2020, 06:41 AM
Last Post: prayuktibid
  Reading JSON - error jmair 2 2,254 May-22-2019, 07:25 PM
Last Post: jmair
  Error message in Jupyter Notebook with json diet 4 5,580 Jun-17-2018, 08:32 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020