Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python XMLRPC question

Reply
Thread Tools

Python XMLRPC question

 
 
prasanna
Guest
Posts: n/a
 
      10-13-2009
In using Python's XMLRPC, there is a statement that gets printed on
stdout of the form:
localhost - - [12/Oct/2009 23:36:12] "POST /RPC2 HTTP/
1.0" 200 -

Where does this message originate? Can I turn it off, or at least
redirect it into a logging file? I am planning to run the server code
automatically at start up and wouldn't have a terminal window open to
get this message. I guess I could redirect/pipe it to a file, but it
would be more useful I could send it to the same log file that I have
the server writing other messages to.

Thanks for any help.
 
Reply With Quote
 
 
 
 
Falcolas
Guest
Posts: n/a
 
      10-13-2009
On Oct 13, 12:47*pm, prasanna <prasa...@ix.netcom.com> wrote:
> In using Python's XMLRPC, there is a statement that gets printed on
> stdout of the form:
> * * * * * * * * *localhost - - [12/Oct/2009 23:36:12] "POST /RPC2 HTTP/
> 1.0" 200 -
>
> Where does this message originate? Can I turn it off, or at least
> redirect it into a logging file? I am planning to run the server code
> automatically at start up and wouldn't have a terminal window open to
> get this message. I guess I could redirect/pipe it to a file, but it
> would be more useful I could send it to the same log file that I have
> the server writing other messages to.
>
> Thanks for any help.


Looking back through the SimpleXMLRPCServer code, it appears that this
happens if the logRequests parameter in the SimpleXMLRPCServer class
initialization is set to True, which it is by default. The underlying
implementation of the logging is in BaseHTTPServer.py, which uses
sys.stderr.

Looks like the simplest way to change that would be to inherit from
the SimpleXMLRPCRequestHandler class and implement your own
log_request method. You could then pass that to the SimpleXMLRPCServer
constructor.

Garrick
 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      10-13-2009
En Tue, 13 Oct 2009 16:55:09 -0300, Falcolas <> escribió:

> On Oct 13, 12:47*pm, prasanna <prasa...@ix.netcom.com> wrote:
>> In using Python's XMLRPC, there is a statement that gets printed on
>> stdout of the form:
>> * * * * * * * * *localhost - - [12/Oct/2009 23:36:12] "POST /RPC2 HTTP/
>> 1.0" 200 -
>>
>> Where does this message originate? Can I turn it off, or at least
>> redirect it into a logging file? I am planning to run the server code
>> automatically at start up and wouldn't have a terminal window open to
>> get this message. I guess I could redirect/pipe it to a file, but it
>> would be more useful I could send it to the same log file that I have
>> the server writing other messages to.
>>
>> Thanks for any help.

>
> Looking back through the SimpleXMLRPCServer code, it appears that this
> happens if the logRequests parameter in the SimpleXMLRPCServer class
> initialization is set to True, which it is by default. The underlying
> implementation of the logging is in BaseHTTPServer.py, which uses
> sys.stderr.
>
> Looks like the simplest way to change that would be to inherit from
> the SimpleXMLRPCRequestHandler class and implement your own
> log_request method. You could then pass that to the SimpleXMLRPCServer
> constructor.


I think it's easier to pass logRequests=False when creating the server.

--
Gabriel Genellina

 
Reply With Quote
 
Falcolas
Guest
Posts: n/a
 
      10-13-2009
On Oct 13, 2:22*pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> En Tue, 13 Oct 2009 16:55:09 -0300, Falcolas <garri...@gmail.com> escribió:

[snip]
> > Looks like the simplest way to change that would be to inherit from
> > the SimpleXMLRPCRequestHandler class and implement your own
> > log_request method. You could then pass that to the SimpleXMLRPCServer
> > constructor.

>
> I think it's easier to pass logRequests=False when creating the server.
>
> --
> Gabriel Genellina


Indeed - I should probably be more explicit that my thoughts were
aimed at logging into their own file.

Garrick
 
Reply With Quote
 
prasanna
Guest
Posts: n/a
 
      10-15-2009
On Oct 13, 1:22*pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> En Tue, 13 Oct 2009 16:55:09 -0300, Falcolas <garri...@gmail.com> escribió:
>
>
>
>
>
> > On Oct 13, 12:47*pm,prasanna<prasa...@ix.netcom.com> wrote:
> >> In using Python's XMLRPC, there is a statement that gets printed on
> >> stdout of the form:
> >> * * * * * * * * *localhost - - [12/Oct/2009 23:36:12] "POST /RPC2 HTTP/
> >> 1.0" 200 -

>
> >> Where does this message originate? Can I turn it off, or at least
> >> redirect it into a logging file? I am planning to run the server code
> >> automatically at start up and wouldn't have a terminal window open to
> >> get this message. I guess I could redirect/pipe it to a file, but it
> >> would be more useful I could send it to the same log file that I have
> >> the server writing other messages to.

>
> >> Thanks for any help.

>
> > Looking back through the SimpleXMLRPCServer code, it appears that this
> > happens if the logRequests parameter in the SimpleXMLRPCServer class
> > initialization is set to True, which it is by default. The underlying
> > implementation of the logging is in BaseHTTPServer.py, which uses
> > sys.stderr.

>
> > Looks like the simplest way to change that would be to inherit from
> > the SimpleXMLRPCRequestHandler class and implement your own
> > log_request method. You could then pass that to the SimpleXMLRPCServer
> > constructor.

>
> I think it's easier to pass logRequests=False when creating the server.
>
> --
> Gabriel Genellina


Thanks. That helped get rid of the message.

Out of curiosity--one more thing I haven't yet figured out, is there a
xmlrpc command I can send that stops or restarts the server?

--p
 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      10-15-2009
En Wed, 14 Oct 2009 22:08:09 -0300, prasanna <>
escribió:

> Out of curiosity--one more thing I haven't yet figured out, is there a
> xmlrpc command I can send that stops or restarts the server?


If you're using Python 2.6, the easiest way is to register its shutdown()
method. Note that it *must* be called from a separate thread (just inherit
from ForkingMixIn)

On earlier versions, overwrite the serve_forever loop (so it reads `while
not self._quit: ...`) and add a shutdown() method that sets self._quit to
True. You'll need to call shutdown twice in that case.

=== begin xmlrpcshutdown.py ===
import sys

def server():
from SocketServer import ThreadingMixIn
from SimpleXMLRPCServer import SimpleXMLRPCServer

# ThreadingMixIn must be included when publishing
# the shutdown method
class MyXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
pass

print 'Running XML-RPC server on port 8000'
server = MyXMLRPCServer(("localhost", 8000),
logRequests=False, allow_none=True)
# allow_none=True because of shutdown
server.register_function(lambda x,y: x+y, 'add')
server.register_function(server.shutdown)
server.serve_forever()

def client():
from xmlrpclib import ServerProxy

print 'Connecting to XML-RPC server on port 8000'
server = ServerProxy("http://localhost:8000")
print "2+3=", server.add(2, 3)
print "asking server to shut down"
server.shutdown()

if sys.argv[1]=="server": server()
elif sys.argv[1]=="client": client()
=== end xmlrpcshutdown.py ===


C:\TEMP>start python xmlrpcshutdown.py server

C:\TEMP>python xmlrpcshutdown.py client
Connecting to XML-RPC server on port 8000
2+3= 5
asking server to shut down

C:\TEMP>

--
Gabriel Genellina

 
Reply With Quote
 
prasanna
Guest
Posts: n/a
 
      10-15-2009
Thanks a bunch. Qill give it a shot.

--p

On Oct 14, 8:18*pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> En Wed, 14 Oct 2009 22:08:09 -0300,prasanna<prasa...@ix.netcom.com> *
> escribió:
>
> > Out of curiosity--one more thing I haven't yet figured out, is there a
> > xmlrpc command I can send that stops or restarts the server?

>
> If you're using Python 2.6, the easiest way is to register its shutdown() *
> method. Note that it *must* be called from a separate thread (just inherit *
> *from ForkingMixIn)
>
> On earlier versions, overwrite the serve_forever loop (so it reads `while *
> not self._quit: ...`) and add a shutdown() method that sets self._quit to *
> True. You'll need to call shutdown twice in that case.
>
> === begin xmlrpcshutdown.py ===
> import sys
>
> def server():
> * * *from SocketServer import ThreadingMixIn
> * * *from SimpleXMLRPCServer import SimpleXMLRPCServer
>
> * * *# ThreadingMixIn must be included when publishing
> * * *# the shutdown method
> * * *class MyXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
> * * * * *pass
>
> * * *print 'Running XML-RPC server on port 8000'
> * * *server = MyXMLRPCServer(("localhost", 8000),
> * * * * *logRequests=False, allow_none=True)
> * * * * *# allow_none=True because of shutdown
> * * *server.register_function(lambda x,y: x+y, 'add')
> * * *server.register_function(server.shutdown)
> * * *server.serve_forever()
>
> def client():
> * * *from xmlrpclib import ServerProxy
>
> * * *print 'Connecting to XML-RPC server on port 8000'
> * * *server = ServerProxy("http://localhost:8000")
> * * *print "2+3=", server.add(2, 3)
> * * *print "asking server to shut down"
> * * *server.shutdown()
>
> if sys.argv[1]=="server": server()
> elif sys.argv[1]=="client": client()
> === end xmlrpcshutdown.py ===
>
> C:\TEMP>start python xmlrpcshutdown.py server
>
> C:\TEMP>python xmlrpcshutdown.py client
> Connecting to XML-RPC server on port 8000
> 2+3= 5
> asking server to shut down
>
> C:\TEMP>
>
> --
> Gabriel Genellina


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python xmlrpc: cannot handle connection errors xristoph@googlemail.com Python 0 07-24-2006 03:54 PM
Re: [Twisted-Python] xmlrpc deferred Jp Calderone Python 0 05-27-2005 07:46 PM
xmlrpc with Python and large datases writeson Python 5 03-23-2005 04:02 PM
Python xmlrpc servers? ted holden Python 9 12-01-2004 08:45 PM
Re: xmlrpc, httplib and SSL (HTTP 1.1 XMLRPC client) Etienne Posthumus Python 1 04-01-2004 05:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57