PyUNO connection to OpenOffice

Enrique Castro ecastro at dbbf.ulpgc.es
Tue Jun 10 09:29:38 EDT 2003


 >>No I can't. "telnet localhost" or "telnet 127.0.0.1" failed
 >>After a little exploration I found "telnet service
 >>management" under administrative tools (I am translating
 >>from names in spanish), and turned on the telnet service.
 >>Now if I do
 >>c:>telnet localhost , I do connect to 127.0.0.1
 >>But
 >>c:>telnet localhost:2002 (or whatever other number) fails
 >
 >
 > Under Windowws, 'telnet' takes its port argument without
 > the colon separator.  Try this instead:
 >
 >  telnet localhost 2002
 >
 > You can also type "netstat -an" and see whether there is
 > anything LISTENING on port 2002, either on 127.0.0.1, your
 > regular address, or 0.0.0.0 (which means "any interface").
 >


I am a newbie and these details are a world for me. Thanks 
to Skip and Peter for being patient with my ignorance.

After checking "netstat -an", as suggested, there is NO 
entry for anythig listening at port 2002. Either OpenOffice 
is running or not.

Now the main question is how to access OpenOffice from 
Python. Why PyUNO fails with the error:

c:\Archivos de programa\OpenOffice.org1.1\program>python 
swriter.py
Traceback (most recent call last):
   File "swriter.py", line 27, in ?
     smgr = resolver.resolve( 
"uno:socket,host=localhost,port=2002;urp;StarOffice
.ServiceManager" )
__main__.com.sun.star.connection.NoConnectException: 
Connector : couldn't connec
t to socket (WSAECONNREFUSED, Connection refused)

The swriter.py script should start a new OpenOffice 
instance, so I do not really understand what should be 
listening at :2002.

What do I need to setup to get the PyUNO connection working?
(I have appended the offending Python code at the end of the 
message)

Is there a way to access OpenOffice through COM? (I have 
used COM to automate MS-Office). Is there a COM object 
map/tutorial for OpenOffice?

Thanks in advance

Enrique

---
These are the first lines of the swriter.py demo script that 
ships with PyUNO

# bootstrap uno component context 	
import uno
import unohelper

# a UNO struct later needed to create a document
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
from com.sun.star.awt import Size

def insertTextIntoCell( table, cellName, text, color ):
     tableText = table.getCellByName( cellName )
     cursor = tableText.createTextCursor()
     cursor.setPropertyValue( "CharColor", color )
     tableText.setString( text )

localContext = uno.getComponentContext()
unohelper.addComponentsToContext(  localContext , localContext,
				   ("connectr","uuresolver","remotebridge","brdgfctr"),
				   "com.sun.star.loader.SharedLibrary" )
				
resolver = 
localContext.ServiceManager.createInstanceWithContext(
				"com.sun.star.bridge.UnoUrlResolver", localContext )

smgr = resolver.resolve( 
"uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" 
)   <--------- This is the offending line.
remoteContext = smgr.getPropertyValue( "DefaultContext" )






More information about the Python-list mailing list