Jun-10-2020, 09:41 AM
I need to send a Json from a file to a server. The server doesn't allow to send bulk Json, juste one by one. I put my json in a file and I have to send that in a loop one by one.
I have a response 500. below my codes :
{"id": "fbfJHSPpUQD",
"displayName": "ANC 1st visit",
"translations": [
{
"property": "FORM_NAME",
"locale": "pt",
"value": "O SDP é acessível por transporte público?"
},
{
"property": "FORM_NAME",
"locale": "fr",
"value": "Le PPS est-il accessible par les transports en commun ?"
}
]
}
I want to point out that this same Json when I use it in Postman, it works!
I have a response 500. below my codes :
import codecs import json import requests from requests.auth import HTTPBasicAuth BASE_API_ENDPOINT ="https://bookumadesu.org/api/elements/" headers={'Content-type':'application/json'} f = codecs.open('data.txt', 'r','utf-8') lines=f.read() txt=[] txt=lines.split('*') for i in txt : #print(i.replace('\n',' ')) payload=json.loads(i) ID=payload["id"] # sending post request and saving response as response object FINAL_ENDPOINT=BASE_API_ENDPOINT+ID+"/translations" print("EndPoint : ",FINAL_ENDPOINT) print(i) r = requests.put(url = FINAL_ENDPOINT,data=i, auth=HTTPBasicAuth('username', 'xxx'), headers=headers) print("Response ",r.status_code) f.close()The json in My txt file :
{"id": "fbfJHSPpUQD",
"displayName": "ANC 1st visit",
"translations": [
{
"property": "FORM_NAME",
"locale": "pt",
"value": "O SDP é acessível por transporte público?"
},
{
"property": "FORM_NAME",
"locale": "fr",
"value": "Le PPS est-il accessible par les transports en commun ?"
}
]
}
I want to point out that this same Json when I use it in Postman, it works!
