region convert config script in python

Started by bungaman, September 11, 2024, 10:02:16 AM

Previous topic - Next topic

bungaman

I'm experimenting with the script convert_regions.config and it works nicely from the command line.

I would like to run it from a python script, but I'm not having any luck getting the command line to parse the config file input without error...

Using subprocess here is the 'command' variable pre-submission print-out:
exiftool -config /Users/bunga/Documents/GitHub/ttp-python-utils/convert_regions.config '-RegionInfoMP<MWGRegion2MPRegion' -overwrite_original /Users/bunga/Documents/GitHub/ttp-python-utils/exiftesting/april1.jpg

result = subprocess.run(command)
And I get...

Error: File not found - '-RegionInfoMP<MWGRegion2MPRegion'
ExifTool returned non-zero exit status: 1

Then if I remove the quotes around the conversion instruction:
exiftool -config /Users/bunga/Documents/GitHub/ttp-python-utils/convert_regions.config -RegionInfoMP<MWGRegion2MPRegion -overwrite_original /Users/bunga/Documents/GitHub/ttp-python-utils/exiftesting/april1.jpg

It appears to run ok and does update the MP region:
1 image files updated

But... then I get this exception from the subprocess execution:
Error converting regions: argument of type 'NoneType' is not iterable

Any ideas on how to avoid the error condition? Is it an error in the XMP region data or in the way I'm calling the command?

(I'd also like to use pyexiftool for efficiency... but wanted to get the workflow going)

StarGeek

I can't help with the Python issue, but the error of
Error: File not found - '-RegionInfoMP<MWGRegion2MPRegion'
means that somehow, '-RegionInfoMP<MWGRegion2MPRegion' is not being interpreted as an exiftool operation. Instead, it is passed to exiftool, quotes included, as if it was a filename. Remember, the single quotes are processed by the command line in order to prevent file redirection with the <.  Exiftool does not see these quotes, as the command line removes them before passing -RegionInfoMP<MWGRegion2MPRegion to exiftool.

You don't show your code where you set the command variable, but according to ChatGPT (chat link), it should look like this. Notice that there are no single quotes around the tag copy operation
command = [
    "exiftool",
    "-config", "/Users/bunga/Documents/GitHub/ttp-python-utils/convert_regions.config",
    "-RegionInfoMP<MWGRegion2MPRegion",
    "-overwrite_original",
    "/Users/bunga/Documents/GitHub/ttp-python-utils/exiftesting/april1.jpg"

The response of
Error converting regions: argument of type 'NoneType' is not iterableis not an exiftool error. Searching, this looks like it's a Python error. Maybe see this StackOverflow question.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

bungaman

Thanks @StarGeek - the error was coming from a print command (result message) AFTER the command was executed.

Now I will try with pyexiftool.