how to get response from python to HTML

Solved!
ananth
Level 3
how to get response from python to HTML

Hi,

 

how to get response or error from python to HTML and alert that message in HTML/JS?

 

for e.g if i create project using python API create_project(project_keynameownerdescription=Nonesettings=Noneproject_folder_id=None) and this successfully created or failed how to get the response back to HTML and alert as successfully created or failed with exception as error message in alert box etc?

 

Thanks,

Ananth

1 Solution
Liev
Dataiker Alumni

Hi @ananth 

I don't see your definition in backend for endpoint first_api_call. You can use both the browser console debugger and the Log of the backend to make sure that:

- The backend is being called and reached with parameters

- The backend is processing correctly the request.

- The backend is responding with something valid and that the Front end is receiving this.

I would put loggers and print statements along the way in order to follow that chain of events.

View solution in original post

4 Replies
Liev
Dataiker Alumni

Hi @ananth 

If your API call succeeds, when you create the project using the Python public API, you will do so like this:

import dataiku
client = dataiku.api_client()
new_project = client.create_project('TEST_PROJECT', 'test project', 'tester', description='a simple description')

 as documented here . The new `new_project` object will be of type

dataikuapi.dss.project.DSSProject
If the creation of the project failed, you will receive an error stating the reason for it.
 
ananth
Level 3
Author

Hi @Liev ,

 

thank you for the details project creation was successful and logs as below 

2020-06-29 10:50:14,216 INFO 127.0.0.1 - - [29/Jun/2020 10:50:14] "GET /__ping HTTP/1.1" 200 -
{"requesttype": "DSS Project Creation Form", "Email": "a", "CountryRegion": ""}
2020-06-29 10:50:18,332 INFO 127.0.0.1 - - [29/Jun/2020 10:50:18] "GET /first_api_call?
description=a&requesttype=DSS+Project+Creation+Form&CntryRegn= HTTP/1.1" 200 -

in python

data = json.dumps({"Email": userdescription, "requesttype": requesttype, "CountryRegion": countryRegion})
return json.dumps({"status": "ok", "data": data})

 

in HTML

 

$.getJSON(getWebAppBackendUrl('first_api_call'), {
"description": descriptionText.value, "requesttype": requesttypetext
, "CntryRegn": lstCountryorRegionval
})
.done(
function (data) {
clearMessage();
displayMessage(data);
}
);

 

function displayMessage(messageText, messageClassname) {
var obj = JSON.parse(messageText);
alert(obj);
var messageContainer = document.getElementById('message');
messageContainer.innerHTML = messageText;
//messageContainer.className = '';

}

 

its not displaying the alert message from python return response

 

 

Liev
Dataiker Alumni

Hi @ananth 

I don't see your definition in backend for endpoint first_api_call. You can use both the browser console debugger and the Log of the backend to make sure that:

- The backend is being called and reached with parameters

- The backend is processing correctly the request.

- The backend is responding with something valid and that the Front end is receiving this.

I would put loggers and print statements along the way in order to follow that chain of events.

ananth
Level 3
Author

Hi @Liev ,

thank you! my bad ๐Ÿ˜ฅ, issue was with actually with clearMessage() function, what this function does as below, so it was clearing those, as soon as i commented it worked and able to get the data from python to HTML ๐Ÿ˜€

 

function clearMessage() {
displayMessage('');
}

 

.done(
function (data) {
//clearMessage();
displayMessage(data);
}
);