You are not logged in Log in Join
You are here: Home » Members » lstaffor » Using ZClient to Access Another Server

Log in
Name

Password

 

Using ZClient to Access Another Server

Sometimes you need to get data from another server and serve it as if it came from your server. For example, you want to show the current weather from www.weather.com on the front page of your Intranet site. Or your main server is on Unix, but you want to get data from Microsoft databases on an NT server through another Zope on that machine.

You want to use ZClient, which is located in your Zope directory at ../lib/python/ZPublisher/Client.py. Read the comments to get an idea of how it works. Basically, it acts as a web browser, but returns the fetched page to your program.

Because, ZClient is an external Python program, you have to create an external method to drive it from within DTML. Consult the How-To: Using External Methods to help you add an external Python method similar to this:

from ZPublisher import Client

def web_client(url = 'http://www.yahoo.com/', username = None, password = None, **kw):
     '''access http servers'''
     if kw:
         return Client.call(url,username,password,kw)[1]
     else:
         return Client.call(url,username,password)[1]

My version of this Python code resides at ../Extensions/WebClient.py and the external method is called "webClient".

Create one or more DTML methods that call this external method with the correct parameters to access the other server. Here's a simple example that doesn't require any more parameters than the URL of an SQL method on the database server:

<!--#var standard_html_header-->
<h2><!--#var document_title--></h2>
<dtml-var "webClient('http://nt-server:8080/Marketing/AllCustHave')">
<!--#var standard_html_footer-->

That's all!