PUT request using python not updating when JSON value is a list -


i trying update json value using api. code works when value string, not work when value list.

import requests  url = 'https://api.janitorplace.com' headers = {'access_token': 'adsjfhiushadf8998ehf'} r_info = requests.get(url + contact_id, headers=headers) f=r_info.json()  f['websites'][0]['address']='www.janitors.com' data = {'websites': f['websites']}  r_info2 = requests.put(url + contact_id, data=data, headers=headers) 

before 'address' field modified f['websites'] returns

[{'address': 'www.janitorsarecool.com',   'id': 210018,   'kind': 'website',   'principal': none}] 

and after 'address' field modified f['websites'] returns

[{'address': 'www.janitors.com',   'id': 210018,   'kind': 'website',   'principal': none}] 

this same code works fine if value 'data' string rather list.

import requests  url = 'https://api.janitorplace.com' headers = {'access_token': 'adsjfhiushadf8998ehf'} r_info = requests.get(url + contact_id, headers=headers) f=r_info.json()  data = {'first_name': 'brian'}  r_info2 = requests.put(url + contact_id, data=data, headers=headers) 

the key 'first_name' takes string , key 'websites' takes list of dicts.

how can update 1 value in dict when dict nested in list of dicts , list of dicts value key in json object?

i using python 3.6.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -