Set the AMI to run a Python script?

I’ve used flask to get the data from the AMI and process it with python, but I think other people can also use the AMI to run python to process the data

you can register a custom URL handler in the OS to capture a request and send it to a python file/executable.

So for example MyStudioProcess://ami_handler would point to a python file and executable and run a script.

Here is the documentation:
https://help.autodesk.com/view/SGDEV/ENU/?guid=SGD_ami_custom_browser_protocols_html

If I want my colleague to use the AMI, do I have to register the protocol on his computer and put the Python script on his computer, but also configure the Python interpreter and shotgun_api3, is there a way for him to click on the AMI to run the Python script?

Yes, all the computers you want to use it on need to be set up the same way.
The script could live on a server if needed.

In a windows environnment this is usually something that IT admins can set up using Active Directory and Group Policy.

I follow the documentation Help create an AMI in Flow Production Tracking whose URL value will be shotgrid://processVersion ,The processVersion parameter was not passed into my python script,

You didn’t supply enough details to understand the issue.
The entire url is passed to your script. Then you have to parse out the parts. I recommend using urllib.parse module for this purpose.

Is this on Windows? How did you register the handler?

screenshot-20250221-160046



Yes, it’s windows, that’s how I signed up

Yeah, the full url should be passed to your script in sys.argv


Here’s my code, consistent with the documentation

My python script can receive arguments, but clicking ami in shotgrid and my code doesn’t execute
I’ve tried opening my local app on ShotGrid and it does
I don’t know what the problem is, like you said, the full URL should be passed to your script in sys.argv But my python script didn’t execute

Oh, in this case the protocol registration is probably incorrect. Btw I notice it is ShotGrid and not shotgrid. I believe this part has to match the protocol name. It could be something else related to protocol registration.

I don’t think there’s anything wrong with my protocol because I changed the value under the command to my local maya.exe, and I clicked ami on shotgrid and maya started normally. The name problem, I changed it to the same shotgrid, but it still didn’t start my script, there is a document error on the browser, I don’t know if it matters, it’s the picture above

Is the path to Python correct?
Also you can investigate the error in the browser - might provide some clues.

Python path without spaces, I’m stupid, thanks for helping me solve the problem

1 Like

You could probably package up your flask server in an exe with PyInstaller so the end user doesn’t need to install python etc, works for macOS and Linux too.

And then for the windows reg edit to add the custom URL handler there’s a python module called winreg which allows you to work on the windows registry from python code:

Reproducibility is crucial in a studio environment.

In addition to Matteo’s suggestion, consider using a deployment automation system such as Chef, Ansible, or Salt. Through these, you can centrally manage the setup of all machines at once.

I would wager it’s because of using non UTF-8 characters for the URL handler.

Most OS’s have trouble with different character sets in vital use cases (like protocol handlers).

Same issue would happen if you use non UTF-8 characters in usernames etc.

Try using UTF-8 compliant name and see if tha fixes it.
You also need to reboot your machine for the change to work.