Python Forum
PUT http query return <Response [500]>
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PUT http query return <Response [500]>
#1
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 :

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! Hand
Reply


Messages In This Thread
PUT http query return <Response [500]> - by rndoma - Jun-10-2020, 09:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  POST requests - different requests return the same response Default_001 3 1,957 Mar-10-2022, 11:26 PM
Last Post: Default_001
  Return Frame as well as JSON response using same API in Flask Python Ask jenkins43 0 1,877 May-11-2020, 04:58 PM
Last Post: jenkins43
  Flask return http status code 200 but web browser not recive supernoobs 2 10,745 Dec-29-2018, 09:27 PM
Last Post: Unisoftdev

Forum Jump:

User Panel Messages

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