Python Forum
PUT http query return <Response [500]> - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: PUT http query return <Response [500]> (/thread-27540.html)



PUT http query return <Response [500]> - rndoma - Jun-10-2020

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


RE: PUT http query return <Response [500]> - ChaitanyaPy - Jun-10-2020

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 ?"


RE: PUT http query return <Response [500]> - rndoma - Jun-10-2020

@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).


RE: PUT http query return <Response [500]> - ChaitanyaPy - Jun-10-2020

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.


RE: PUT http query return <Response [500]> - rndoma - Jun-10-2020

(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.


RE: PUT http query return <Response [500]> - ChaitanyaPy - Jun-10-2020

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.


RE: PUT http query return <Response [500]> - rndoma - Jun-10-2020

(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.


RE: PUT http query return <Response [500]> - rndoma - Jun-10-2020

I resolved the problem my self it woks now.
Thanks!