1

Looking over a post from 2015 link on how to use PyExifTool to write to the Exif header. I gave it a try:

import exiftool
fileno=r'DSC00001.JPG
with exiftool.ExifTool() as et:
    et.execute("EXIF:GPSLongitude=100",fileno)
    et.execute("EXIF:GPSLatitude=100",fileno)

In response, I got the following error:

TypeError: sequence item 0: expected a bytes-like object, str found

Then as specified in the documentation, execute takes byte commands, so I bites, so I tried that too:

with exiftool.ExifTool() as et:
   et.execute(bytes("EXIF:GPSLongitude=100", 'utf-8'),fileno)
   et.execute(bytes("EXIF:GPSLatitude=50",'utf-8'),fileno)

But still got the same error :

TypeError: sequence item 1: expected a bytes-like object, str found

I am not sure what am I doing wrong, and if Exiftool can write to file.

StarGeek
  • 4,948
  • 2
  • 19
  • 30
icypy
  • 3,062
  • 5
  • 25
  • 27

2 Answers2

2

The problem is that the execute method is low-level and requires bytes as inputs for both the parameters you pass and the file name. Try this:

import exiftool
pic = b"DSC00001.JPG"
with exiftool.ExifTool() as et:
    et.execute(b"-GPSLatitude=11.1", pic)
    tag = et.get_tag("EXIF:GPSLatitude", pic)
    print(tag)
  • I think your suggestion is in the right direction. Problem is there are some cases when an error is not raised, and I think this is one of them. When I run the code with your suggestions, print(tag) returns NONE. Even if you try et.get_metadata(pic), there is no GPS information. – icypy Jun 20 '18 at 08:06
  • Check my latest edit. To actually write the tag you need to use the form: "-TAG=VALUE" instead of "EXIF:TAG" format. If you use the code above in its current form it should work and "print(tag)" should now return a value. – archaeopteryx Jun 20 '18 at 15:36
0
#Gracias!

    exif = r'...\exiftool.exe'
    file=br"...\FRM_20220111_134802.JPG"
    
    with exiftool.ExifTool(exif) as et:
        et.execute(b"-DateTimeOriginal=2022:10:10 10:10:10", file)
        tag = et.get_tag("EXIF:DateTimeOriginal", file)
        ...

#RCM_Chile
RAUL C.
  • 16