[python-win32] Re: Python-win32 Digest, Vol 53, Issue 6
Roger Upole
rwupole at msn.com
Tue Aug 7 09:26:24 CEST 2007
Huang Guan wrote:
> I need your help on question 3 still:
>
> import pythoncom
> from win32com.server import util
> f=open('somepage.html','r')
> fs=util.FileStream(f)
> istream=util.wrap(fs, pythoncom.IID_IStream )
> p=ie.Document._oleobj_.QueryInterface (pythoncom.IID_IPersistStreamInit)
> p.Load(istream)
>
> p.Load(istream)tested and excuted successful, thank you.
>
> f=open('somepage.html','w+')
> fs=util.FileStream (f)
> istream=util.wrap(fs, pythoncom.IID_IStream)
> p=ie.Document._oleobj_.QueryInterface(pythoncom.IID_IPersistStreamInit)
> p.Save(istream,True)
>
> Why p.Save(istream,True) can excuted, but error massage as below:
> pythoncom error: Unexpected gateway error
> <type 'exceptions.TypeError'>: an integer is required
> check somepage.html file current dir,is exists,size:5kb,
> but the file is not complete html source.
> How to resolve the p.Save() problem?
FileStream's Write method wasn't returning the length as expected.
I just checked in a fix:
http://pywin32.cvs.sourceforge.net/pywin32/pywin32/com/win32com/server/util.py?view=log
> v_StringIO=StringIO.StringIO()
> v_f_object=open(' somepage.html','r')
> v_StringIO.write(v_f_object.read())
> v_f_object.close()
> fs=util.FileStream(v_StringIO)
> istream=util.wrap(fs, pythoncom.IID_IStream)
> p=ie.Document._oleobj_.QueryInterface (pythoncom.IID_IPersistStreamInit)
> p.Load(istream)
>
> p.Load(istream) excuted successfully, but do not get values from v_StringIO,
> why?
>
You need to seek the input stream to the beginning before loading from it.
Roger
More information about the python-win32
mailing list