Select to view content in your preferred language

How to call Python script from ESRI Javascript

868
3
07-31-2022 07:03 AM
Tarunvisvanadula1994
Emerging Contributor

Hi,

is it possible to send a request to python script with custom parameters and catch response what ever script returns using ESRI Javascript 3.x ?

If yes please provided an step for starting.

Requirement : For generating token in python and consuming same token in ESRI web application 

0 Kudos
3 Replies
Brian_Wilson
Honored Contributor

Python can't run in the browser so you have to put it on a server. I've set up specific tasks to do something like that by using Flask (a Python module) to create microservices, the Python accepts HTTP requests and then returns data as JSON or HTML. For example I have it query the ArcGIS License server to find out what concurrent licenses are in use. 

What you are trying to do is best done directly from your Javascript. The Python API that Esri provides is really just a wrapper around the REST services. Look at the "esri" module. 

https://developers.arcgis.com/javascript/3/jsapi/credential-amd.html

They have some OAUTH samples in the Guide section here

https://developers.arcgis.com/javascript/3/jssamples/portal_oauth_inline.html

https://developers.arcgis.com/javascript/3/jssamples/portal_oauth_popup.html

Hope this helps.

 

0 Kudos
shaileshgavathe
Frequent Contributor

If you are talking about generating ESRI Portal token, you don't need a Python for that. ESRI has a Rest API to do just that. 

https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm

 

But if your python script doing more than just generating a token, then consider creating a custom Geoprocessing Tool. Import your python script into the Tool and then publish it to ArcGIS Server. That way it is available to access on the Web and use it.

 

Thanks, 

Brian_Wilson
Honored Contributor

I am so used to setting up Flask microservices that don't require any geoproccessing that I forget it is an option! Thanks @shaileshgavathe