1.error:
{
“title” : “Bad Request”,
“status” : 400,
“detail” : “JSON parse error: Unrecognized token ‘username’: was expecting (‘true’, ‘false’ or ‘null’); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token ‘username’: was expecting (‘true’, ‘false’ or ‘null’)\n at [Source: (PushbackInputStream); line: 1, column: 10]”,
“path” : “/getToken”,
“message” : “error.http.400”
}
2.codes
{
“title” : “Bad Request”,
“status” : 400,
“detail” : “JSON parse error: Unrecognized token ‘username’: was expecting (‘true’, ‘false’ or ‘null’); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token ‘username’: was expecting (‘true’, ‘false’ or ‘null’)\n at [Source: (PushbackInputStream); line: 1, column: 10]”,
“path” : “/getToken”,
“message” : “error.http.400”
}
2.codes
import requests
url = 'http://10.165.153.210/getToken'
headers = {
'Content-Type': 'application/json'
}
payload = {
'username': 'pad_view',
'password': '6368da1213cd4c4538128a0e9acd0288'
}
res = requests.post(url=url,method='post', data=payload, headers=headers)
print(res.text)
3. Reasons
When you request to pass parameters, the JSON string and dictionary look the same, but the background serialization format is different. Therefore, a JSON parsing error will be reported when data is passed in
4. Solutions
Convert dictionary object to JSON string
4.1 import JSON
import json
4.2 convert dictionary object to JSON string
payload = json.dumps({ 'username': 'username', 'password': 'password' })
4.3 complete modification code, as follows
import requests
import json # import json
url = 'http://10.165.153.210/getToken'
headers = {
'Content-Type': 'application/json'
}
# Convert a dictionary object into a json string, using the json.dumps() method
payload = json.dumps({
'username': 'pad_view',
'password': '6368da1213cd4c4538128a0e9acd0288'
})
res = requests.post(url=url,method='post', data=payload, headers=headers)
# Print the response message
print(res.text)
Read More:
- [Solved] SyntaxError:JSON.parse:unexpected character at line 1 column 1 of the JSON data
- [Solved] JSON parse error: Unexpected character (‘‘‘ (code 39)): was expecting double-quote to start ……
- JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token
- How to parse JSON string in.Net [error reading job object from jsonreader. Current jsonreader item is not an obj]
- JSON parse error: raw timestamp (1595952000000) not allowed for
- [Solved] JSON parse error: Unexpected character (‘‘‘ (code 39)): was expecting double-quote to star
- [Go] Solve the empty interface interface{} cannot use (type []string) as type []interface {}
- [Solved] Parsing JSON error unexpected end of JSON input
- Json: struct field readyReplicas has json tag but is not exported [How to Solve]
- ArchLinux starts error after modifying MariaDB database path Can’t create test file /xxxxx/xxxxx-test
- [Solved] There are test failures. Please refer to D:\Java_study\springboot\springboot-sugon-3\target\surefire-reports for the individual test results.
- Solve chrome running error unknown error: cannot get automation extension
- Creating test database for alias ‘postgres’… Got an error creating the test database: permission
- Sentinel could not find the urlblockhandler interface solution
- Sqoop Error: Can‘t parse input data: ‘\N‘ [How to Solve]
- [Solved] MindSpore Error: “TypeError: parse() missing 1 required positional.”
- [Solved] SyntaxError: Unexpected end of JSON input
- Aspecj cannot intercept method annotations on an interface
- DB::Exception: test: Authentication failed: [How to Solve]
- [Solved] Android HTTPS request resource or interface error: server certificate