I'm currently working on a Web API with Flask. The idea is that i get a Json File and i return one after the work is done.
The code is working (it worked before) but I'm currently getting this Error on Postman :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Did not attempt to load JSON data because the request Content-Type was not 'application/json'.</p>
and on the command line i get:
"POST /json HTTP/1.1" 400 -
code 400, message Bad request syntax ('{')
"None /json HTTP/0.9" HTTPStatus.BAD_REQUEST -.
Has anyone an idea what that means ?
Make sure the api server is not problematic.
The answer is in the response message. You made the api request without the appropriate Content-Type header. Just add it and it should work, if the api server has no other issues.
Related
I am trying to create a test plan using jmeter.its for an API Post request, I have a header manager, bodydata, checked for spellings and the syntax seems to be correct. However, Im getting 400 response code with the following error shown in the attached image. Anyone with an idea how I can resolve this? Thank you. the error
Here is the request the request
The user doesn't have to be logged in, i have added a header manager, I have also noticed there header has a cookie value thats hard coded but it appears to be the same in every request. In the UI the API request returns 200 and thats what im expecting with the Jmeter script.
In its current form the question cannot be answered comprehensively.
HTTP Status Code 400 means that
The 400 (Bad Request) status code indicates that the server cannot or
will not process the request due to something that is perceived to be
a client error (e.g., malformed request syntax, invalid request
message framing, or deceptive request routing).
Check that your ${site} and ${csVersion} variables have their respective values using Debug Sampler and View Results Tree listener combination
Cross check headers sent by JMeter and by the "UI", the most important is Content-Type
Use a sniffer tool like Wireshark of Fiddler and capture the requests which are being sent by JMeter and the "UI", the requests must be exactly the same apart from dynamic parameters which need to be correlated
The issues was being caused by an anti-forgery cookie which was hard coded in the request.I used a regex to extract the value from a previous request and used a variable value from the regex to make sure the same value is being passed on to the request that was failing.
Sometimes when accessing the Forge Derivative Service API via
GET https://developer.api.autodesk.com/derivativeservice/v2/manifest/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c3RlbW4vNTcwMzBkMzBjNzFkZWVmNDBkNjViNDAxLTBCOTlVamtJMXBnN2FkbE16UzJKSExVbzNjV3MtMEI5OVVqa0kxcGc3YWRHOTJlbVJtTnpablJ6TnhRV2N5V1hOT05qZEdPV2xwYVhoclBRLXVuZGVmaW5lZC5kd2c
I get the response
<HTML><HEAD>
<TITLE>Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
Reference #7.425832b8.1500624784.0
</BODY>
</HTML>
How can I find out what it was about my request that the server did not understand. This is a simple GET request so I'm not sure what I am doing so that my request is not understood.
First, there is no endpoint like you are describing (see list): derivativeservice/v2/manifest/:urn doesn't exist, aren't you missing something? Which endpoint are you trying to call? Maybe manifest?
Second, when I base64 DECODE your URN, I'm getting:
urn:adsk.objects:os.object:stemn/57030d30c71deef40d65b401-0B99UjkI1pg7adlMzS2JHLUo3cWs-0B99UjkI1pg7adG92emRmNzZnRzNxQWcyWXNONjdGOWlpaXhrPQ-undefined.dwg
This undefined at the end is a bit suspicious and may be causing this problem. Can you double check the URN before encoding it? If that's a file on a bucket, seems incomplete/incorrect anyway.
I've been sniffing some XMPP messages from a system that I'm working on, and am getting messages like the following
<message to="client#address" type="chat" xml:lang="en" from="server#address/RestApi">
<body>HTTP/1.0 200 OK\nContent-Length: 640\nContent-Type: application/json\nconnection: close\n\n
5EBW5RuFo7QojD4F1Uv0kOde1MbeVA46P3RDX6ZEYKaKkbLxanqVR2I8ceuQNbxkgkfzeLgg6D5ypF9jo7yGVRbR/ydf4L4MMTHxvdxBubG5HhiVqJgSc2+7iPvhcWvRZrRKBEMiz8vAsd5JleS4CoTmbN0vV7kHgO2uVeuxtN5ZDsk3/cZpxiTvvaXWlCQGOavCLe55yQqmm3zpGoNFolGPTNC1MVuk00wpf6nbS7sFaRXSmpGQeGAfGNxSxfVPhWZtWRP3/ETi1Z+ozspBO8JZRAzeP8j0fJrBe9u+kDQJNXiMkgzyWb6Il6roSBWWgwYuepGYf/dSR9YygF6lrV+iQdZdyF08ZIgcNY5g5XWtm4LdH8SO+TZpP9aocLUVR1pmFM6m19MKP+spMg8gwPm6L9YuWSvd62KA8ASIQMtWbzFB6XjanGBQpVeMLI1Uzx4wWRaRaAG5qLTda9PpGk8K6LWOxHwtsuW/CDST/hE5jXvWqfVmrceUVqHz5Qcb0sjKRU5TOYA+JNigSf0Z4CIh7xD1t7bjJf9m6Wcyys/NkwZYryoQm99J2yH2khWXyd2DRETbsynr1AWrSRlStZ5H9ghPoYTqvKvgWsyMVTxbMOht86CzoufceI2W+Rr9
</body></message>
I don't really understand what I've got here: it seems to be a XMPP message which is somehow encoding the result of a REST API call that returns JSON. The body of the message seems to be just a HTTP response (basically they seem to have just shoved the HTTP response directly into a XMPP message), but it definitely doesn't look like JSON to me!
I've tried doing a base64 decode of the data within the HTTP response, but it doesn't come up with anything sensible.
Does anyone have any idea how to decode this data? I assume JSON is hidden in there somewhere, but I can't see how or where.
Does anyone know what is the best format to return an HTTP response error to the client when facing an exception? A format to handle the error in a dynamic way and the easiest way to catch the exception between server and client
i suggested the following, but i need to get the best format for the error response:
{
"FLAG": "ERROR",
"TEXTEN": "SERVER ERROR – BAD REQUEST"
}
One good solution would be to send back the error code in the answer's headers, using the standardized HTTP codes from the HTTP protocol.
You can also add you own error code and a corresponding human readable message in the JSON body to provide more informations on the encountered error.
For example, for a Bad Request error, the corresponding HTTP code is 400. So you should send back the HTTP code 400 in the response header and the corresponding HTTP message (Bad Request). But some programming languages does not offer out of the box features to read the message. To be sure that the user can read it properly, you can also put it in the JSON body if you want.
I'm attempting to use the add_run API method to create new test runs on my testrail server. I am using RESTClient to test the command.
The request is POST index.php?/api/v2/add_run/1
(I have a project with id 1)
As request headers I am using Content-Type: application/json and Authorization: Basic USERNAME:PASSWORD_BASE64
request body is:
{
"name":"name",
"suite_id":1
}
Upon sending the request, I receive a "400 Bad Request" Response with the error message:
{"error":"Content-Type header invalid (use Content-Type: application\/json)"}
Since I am in fact using Content-Type: application/json as a request header I have no idea why I am getting this error or what it means. Anyone have any ideas?
one of the TestRail developers here. It's very likely that you didn't submit the Content-Type header correctly, could you please share the source snippet you used to send this request?