pythonwindowsexiftoolwsastartup

WSAStartup error (10093) when calling exiftool through PyExifTool


I have installed PyExifTool (https://smarnach.github.io/pyexiftool/). The installation was successful. However, when I try to run the example code provided there:

import exiftool

files = ["test.jpg"]
with exiftool.ExifTool() as et:
    metadata = et.get_metadata_batch(files)
for d in metadata:
    print("{:20.20} {:20.20}".format(d["SourceFile"],
                                     d["EXIF:DateTimeOriginal"]))

I am getting this error:

Traceback (most recent call last):
  File "extract_metadata_03.py", line 5, in <module>
    metadata = et.get_metadata_batch(files)
  File "c:\Python38\lib\site-packages\exiftool.py", line 264, in get_metadata_batch
    return self.execute_json(*filenames)
  File "c:\Python38\lib\site-packages\exiftool.py", line 256, in execute_json
    return json.loads(self.execute(b"-j", *params).decode("utf-8"))
  File "c:\Python38\lib\site-packages\exiftool.py", line 227, in execute
    inputready,outputready,exceptready = select.select([fd],[],[])
OSError: [WinError 10093] Either the application has not called WSAStartup, or WSAStartup failed

I have tried with exiftool.exe Version 11.91 stand-alone Windows executable (from https://exiftool.org/) in my path as well as installing exiftool using Oliver Betz's ExifTool Windows installer (https://oliverbetz.de/pages/Artikel/ExifTool-for-Windows)

I have tried two separate Python installations (Python 3.8 and also Python 2.7) with the same behaviour.

Any assistance with this or suggestions for troubleshooting would be greatly appreciated.


Solution

  • You get the error because the select.select() used in exiftool.py is not compatible with Windows. To solve this you can manually add the following to exiftool.py:

    if sys.platform == 'win32':
        # windows does not support select() for anything except sockets
        # https://docs.python.org/3.7/library/select.html
        output += os.read(fd, block_size)
    else:
        # this does NOT work on windows... and it may not work on other systems... in that case, put more things to use the original code above
        inputready,outputready,exceptready = select.select([fd],[],[])
        for i in inputready:
            if i == fd:
                output += os.read(fd, block_size)
    
    

    Source: https://github.com/sylikc/pyexiftool/commit/03a8595a2eafc61ac21deaa1cf5e109c6469b17c