I'd like to save a docx template on samba share drive.
I'm currently using smbclient for that.
import smbclient #pip install smbprotocol
with smbclient.open_file(r"\\servername\share\myfile.txt", mode='w') as fd :
fd.write(u"this works")
but now instead of writing a txt file, I want to write my docx template :
from docxtpl import DocxTemplate
template_docx = DocxTemplate(template_name)
template_docx.render(data)
template_docx.save('myfile.docx') # this works
with smbclient.open_file(r"\\servername\share\myfile.docx",mode='w') as fd :
template_docx.save(fd) # this does not work
I really don't understand how smbclient works and if it's even possible.
Can I even copy a file to from my machine to my smb drive using smbclient ? If so, that can be a workaround
I also tried smb.SMBConnection but it doesn't work (SMB connection not authenticated)
error message :
write() argument must be str, not bytes
Exception ignored in: <function ZipFile.__del__ at 0x000001BA237FE020>
Traceback (most recent call last):
File "C:\Program Files\Python311\Lib\zipfile.py", line 1874, in __del__
self.close()
File "C:\Program Files\Python311\Lib\zipfile.py", line 1891, in close
self.fp.seek(self.start_dir)
ValueError: I/O operation on closed file.