[Python] Python pefile Write failure

Discussão em 'Python' iniciado por Stack, Março 3, 2025.

  1. Stack

    Stack Membro Participativo

    Fails on machine 1 but not on other machine.s The files are all hosted on machine 1 on a shared drive.

    import sys
    import pefile

    pe = pefile.PE(sys.argv[1])
    pe.write (sys.argv[1])
    print "Finished!"


    It fails on machine 1 with

    pe.write (sys.argv[1])
    File "n:\Python27\pefile.py", line 2155, in write
    f = file(filename, 'wb+')
    IOError: [Errno 22] invalid mode ('wb+') or filename: 'notepad.exe'


    (excerpt form pefile

    f = file(filename, 'wb+')
    f.write(new_file_data)
    f.close()


    )

    (but this works fine

    f = file(sys.argv[1], 'wb+')
    f.write("Hello World")
    f.close()


    )

    Admitted this may not be a Python issue, I'm a bit stumped. The host machine is Windows Server 2016, client machines are Win 8 and Win 10 pro. I've tried a few different exes.

    Edit - I retargetted this at Python 3.10 with the same result, except the error is slightly different

    File "n:\python310\lib\site-packages\pefile.py", line 3325, in write
    f = open(filename, "wb+")
    OSError: [Errno 22] Invalid argument: 'notepad.exe'

    Continue reading...

Compartilhe esta Página