Post request returns error 500

Asked

Viewed 63 times

0

I have a simple Python script that sends a post request with a certain payload but it returns error 500. I’d really like someone to help me.

The code:

def answered(self,answer):
    headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
    "apikey": "<API KEY HERE>",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Content-Length": "69",
    "Content-Type": "application/json;charset=UTF-8",
    "device-Id": "b0fa2eee-66ba-4b23-99fe-c2cfeee7cc70",
    "Host": "giga.unitel.ao",
    "If-Modified-Since": "Mon, 26 Jul 1997 05:00:00 GMT",
    "Origin": "http://giga.unitel.ao",
    "Pragma": "no-cache",
    "Referer": "http://giga.unitel.ao/",
    "token": "<TOKEN HERE>",
    "txId": "d9f98598-0251-4319-88ed-ef729ec872ec",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36",

    }
    payload = {
        "moveId":4628870481,
        "index":1,
        "help":"null",
        "time": 20,
        "optional":"null"
    }
    answer = requests.post("http://giga.unitel.ao/api/game/answer",data=payload, headers=headers)
    print(answer)

URL portal: http://giga.unitel.ao

  • @imonferrari, here’s another question!

  • Error 500 is server error. You can point to the API documentation of this site?

1 answer

1

Something in the headers must be wrong. Try to leave it with as little as possible, as below, for test questions.

headers = {
    "apikey": "<API TESTE HERE>",
    "Content-Type": "application/json; charset=UTF-8",
    "device-Id": "b0fa2eee-66ba-4b23-99fe-c2cfeee7cc70",
    "token": "<TOKEN HERE>",
    "txId": "d9f98598-0251-4319-88ed-ef729ec872ec",
}

payload = {
    "moveId": 4628870481,
    "index": 1,
    "help": "null",
    "time": 20,
    "optional": "null"
}


answer = requests.post("http://giga.unitel.ao/api/game/answer", data=payload, headers=headers)
print(answer.json())

The response obtained was:

{'responseData': {'errorCode': 'INVALID_TOKEN', 'errorMessage': 'Invalid token.'}, 'responseCode': '400', 'inError': True, 'requestId': 'd9f98598-0251-4319-88ed-ef729ec872ec', 'additionalFields': {}}

Work from here. I believe something over the header is generating the error on the server.

I hope it helps.

  • "Something in the headers must be wrong" this is probably the reason, but only the server returns 500 which means internal server error already suggests that the guys programmed the API equal their nose, had to validate the parameters passed and if there is any problem in them resume the appropriate code of the HTTP protocol for this, I do not remember what it is now, must be 4xx something. Although it may be other reasons, a failure to access the database, for example.

  • @Piovezan, I agree that "breaking" the server by incompatible header is a programming problem in the API...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.