'Python Error when doing post request in NodeJS
Currently, there is a machine learning backend program in Python, which is run on Google Cloud.The app takes following arguments: arguments
lang: "EN", //language
base64: BASE64, //Whether the image is base64 or not
width: 224, //width (always 224)
height: 224, //height (always 224)
channel: 3, // channels (always 3)
image: image_final //BAse64 string of an image
The program reads an image and returns the location of damage (if found) and the severity of it.
The goal is to implement this in a chatbot. This means I have to do a POST request to send data to this app.
In nodejs, I have the following code:
`const payload = {
lang: "EN",
base64: true,
width: 224,
height: 224,
channel: 3,
image: image_final,
}
let options = {
method: "POST",
url: "https://BASEURL/CarDamageClassification",
data: payload,
headers: { "Content-Type": "application/json" }
}
axios
.request(options)
.then(function (response) {
console.log(response.response)
})
.catch(function (error) {
console.log(error)
})
`
However, when this call is made, an error occurs in Python:
(`2022-03-02 13:29:23.000 CET
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/app/Claims_Car_FNOL.py", line 32, in CarDamageClassify
language = payload( 'lang']
TypeError: 'NoneType' object is not subscriptable
`)
In Nodejs, another error message occurs (Error: Request failed with status code 500) + some extra parameters. Somewhere I found this: data: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n' + '<title>500 Internal Server Error</title>\n' + '<h1>Internal Server Error</h1>\n' + '<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n'
I'm kinda stuck on this issue and I don't know where thinfs are going wrong :(. Thank you in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
