[Solved] DocumentConverty.py 'NoneType' no 'initialize' attr

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
GEM
Posts: 2
Joined: Wed Nov 10, 2010 12:03 pm

[Solved] DocumentConverty.py 'NoneType' no 'initialize' attr

Post by GEM »

Hi,
I use a module python from openerp named report_openoffice_helper (i'm not the author).
This module use uno bridge and file DocumentConverter.py modified, but I have this error when I try to connect to openoffice :

'NoneType' object has no attribute 'initialize'

in fact the error comes from this line :
self.inputStream.initialize((uno.ByteSequence(stdinBytes),))
in the original code DocumentConverter.py, this is :
inputStream.initialize((uno.ByteSequence(stdinBytes),)) and is in an other function than def __init__ like in modified code

see the modified code for class DocumentConverter:

Code: Select all

class DocumentConverter:
   
    def __init__(self, stdinBytes, host='localhost', port=DEFAULT_OPENOFFICE_PORT):
        self.localContext = uno.getComponentContext()
        self.serviceManager = self.localContext.ServiceManager
        resolver = self.serviceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.localContext)
        try:
            context = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
        except IllegalArgumentException, exception:
            raise DocumentConversionException, "The url is invalid (%s)" % exception
        except NoConnectException, exception:
            raise DocumentConversionException, "Failed to connect to OpenOffice.org on port %s. %s" % (port, exception)
        except ConnectionSetupException, exception:
            raise DocumentConversionException, "Not possible to accept on a local resource (%s)" % exception
        self.desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)

        self.inputStream = self.serviceManager.createInstanceWithContext("com.sun.star.io.SequenceInputStream", self.localContext)
        self.inputStream.initialize((uno.ByteSequence(stdinBytes),))
        self.document = self.desktop.loadComponentFromURL('private:stream', "_blank", 0, self._toProperties(InputStream = self.inputStream))
original code :

Code: Select all

class DocumentConverter:
   
   def __init__(self, port=DEFAULT_OPENOFFICE_PORT):
      self.localContext = uno.getComponentContext()
      self.serviceManager = self.localContext.ServiceManager
      resolver = self.serviceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.localContext)
      try:
         context = resolver.resolve("uno:socket,host=localhost,port=%s;urp;StarOffice.ComponentContext" % port)
      except NoConnectException, exception:
         raise Exception, "Failed to connect to OpenOffice.org on port %s. %s" % (port, exception)
      self.desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)

   def convertByStream(self, stdinBytes, filterName="writer8"):
      inputStream = self.serviceManager.createInstanceWithContext("com.sun.star.io.SequenceInputStream", self.localContext)
      inputStream.initialize((uno.ByteSequence(stdinBytes),))

      document = self.desktop.loadComponentFromURL('private:stream', "_blank", 0, self._toProperties(
         InputStream=inputStream,
         Hidden=False))
complete modified code :
http://bazaar.launchpad.net/~report-ope ... nverter.py

complete original code :
http://www.oooforum.org/forum/viewtopic.phtml?t=109519

Thanks for help or ideas to solve my problem.
Bye
Last edited by GEM on Mon Nov 15, 2010 10:50 am, edited 1 time in total.
openoffice 3.2 vista
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: documentconverty.py 'NoneType' no attribute 'initialize

Post by hanya »

Check the service in the list of available service names.

Code: Select all

print("com.sun.star.io.SequenceInputStream" in self.serviceManager.getAvailableServiceNames())
If it shows False, check your environmental variables.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
GEM
Posts: 2
Joined: Wed Nov 10, 2010 12:03 pm

Re: documentconverty.py 'NoneType' no attribute 'initialize

Post by GEM »

Hi hanya,
thanks for your reply,
you're right, it's just a problem of environment variable.
UNO_PATH C:\Program Files\OpenOffice.org 3\program\
URE_BOOTSTRAP vnd.sun.star.pathname:C:\Program Files\OpenOffice.org 3\program\fundamental.ini
PYTHONPATH C:\Program Files\OpenOffice.org 3\program;C:\Program Files\OpenOffice.org 3\Basis\program;C:\Program Files\OpenOffice.org 3\URE\bin\
Path C:\Program Files\OpenOffice.org 3\program;C:\Program Files\OpenOffice.org 3\Basis\program\;C:\Program Files\OpenOffice.org 3\URE\bin
Now it is solved (but i have a runtime error now with soffice.bin).
Thanks again.
Happy day and hello from France :D

Baibai
openoffice 3.2 vista
Post Reply