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
#2
It is a problem with the server end. Maybe the server is unable to handle the request.
The HTTP Error 500 literally means that. If the server is a python-based server built with services like Pythonanywhere, then recheck your server-side code.
If it's an external service, then check their API documentation.

And are you sure that there is nothing wrong with JSON file?
Because it contains non-English characters like "value": "O SDP é acessível por transporte público?" and "value": "Le PPS est-il accessible par les transports en commun ?"
Reply
#3
@ChaitanyaPy,
The server is a java-base server.
I sent the same Json with Postman, It worked.
Thanks

(Jun-10-2020, 09:58 AM)ChaitanyaPy Wrote: It is a problem with the server end. Maybe the server is unable to handle the request.
The HTTP Error 500 literally means that. If the server is a python-based server built with services like Pythonanywhere, then recheck your server-side code.
If it's an external service, then check their API documentation.

And are you sure that there is nothing wrong with JSON file?
Because it contains non-English characters like "value": "O SDP é acessível por transporte público?" and "value": "Le PPS est-il accessible par les transports en commun ?"

No, I told you I sent the sams Json in Postman. It's the translation of an Element in 2 languages (portugeuse and french).
Reply
#4
Have you checked the API documentation of that service? I have experience using python-based servers, and most of the time the reason for a HTTP Error 500 has always been a server-side code error which I myself have made.
Reply
#5
(Jun-10-2020, 10:35 AM)ChaitanyaPy Wrote: Have you checked the API documentation of that service? I have experience using python-based servers, and most of the time the reason for a HTTP Error 500 has always been a server-side code error which I myself have made.

I told you that it's a Java-based server not Python-based server.
Reply
#6
Is it an online service or a local java-server that you are running? If it's an online service, then there should at least be some bare documentation on what request method to use for a specific function and stuff. Like some instructions on what will work and what won't.
And while scrolling through your code, I saw the endpoint and tried to just go their site for some help.
Then Chrome replied with an error that basically says that the server can't be reached.
Then I tried to request the server with Python, which ended up with a bunch of errors ending with:
Error:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='bookumadesu.org', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000219AF008460>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
.
Which got me to thinking if the endpoint even exists?
I am sorry if I am just thinking all of this in the wrong way.
Reply
#7
(Jun-10-2020, 11:12 AM)ChaitanyaPy Wrote: Is it an online service or a local java-server that you are running? If it's an online service, then there should at least be some bare documentation on what request method to use for a specific function and stuff. Like some instructions on what will work and what won't.
And while scrolling through your code, I saw the endpoint and tried to just go their site for some help.
Then Chrome replied with an error that basically says that the server can't be reached.
Then I tried to request the server with Python, which ended up with a bunch of errors ending with:
Error:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='bookumadesu.org', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000219AF008460>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
.
Which got me to thinking if the endpoint even exists?
I am sorry if I am just thinking all of this in the wrong way.

Please can you cheick your email please? I sent you an email please.
Reply
#8
I resolved the problem my self it woks now.
Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Return Frame as well as JSON response using same API in Flask Python Ask jenkins43 0 899 May-11-2020, 04:58 PM
Last Post: jenkins43
  Flask return http status code 200 but web browser not recive supernoobs 2 5,968 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