[Zope] Embedding ZPublisher - problem!

Andreas Jung andreas at andreas-jung.com
Tue Apr 27 04:26:27 EDT 2004


Hi,

I am fighting a bit with a ZPublisher problem:

I have a Data.fs containting a script /folder/folder2/myscript which just
performs a "return context.REQUEST.text()".

I want to call this script directly through the ZPublisher (not using 
ZServer) since
Zope should be embedded into another application. I tried that:


import sys
import Zope
from cStringIO import StringIO

from ZPublisher import publish_module
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse
import Zope
Zope.configure('/home/ajung/sandboxes/Zope/Zope/etc/zope.conf')

IO = StringIO()

env = {'HTTP_ACCEPT': 
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1',
'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) 
Gecko/20040207 Firefox/0.8',
 'CONNECTION_TYPE': 'keep-alive',
 'HTTP_COOKIE': 'photo_display=original; __ac_name="ajung"; 
__ac="YWp1bc6cG5t0ZXI%3D%0A"; LOCALIZER_LANGUAGE="de"; I18N_LANGUAGE="de"; 
_ZopeId="38169570A1SGoNv2S0Q"',
'SERVER_NAME': 'localhost',
'GATEWAY_INTERFACE': 'CGI/1.1',
'HTTP_ACCEPT_LANGUAGE': 'de',
'HTTP_KEEP_ALIVE': '300',
'REMOTE_ADDR': '127.0.0.1',
'SERVER_SOFTWARE': 'Zope/(unreleased version, python 2.3.3, linux2) 
ZServer/1.1',
'SCRIPT_NAME': '',
'HTTP_AUTHORIZATION':
'Basic YWRtaW46MTIz',
'REQUEST_METHOD': 'GET',
'HTTP_HOST': 'sentinel:8080',
'PATH_INFO': '/folder/folder2/mytest',
'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.1',
'channel.creation_time': 1082964215,
'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
'PATH_TRANSLATED': '/folder/folder2/mytest'}

name = 'Zope'
response = HTTPResponse()
request = HTTPRequest(IO, environ=env, response=response)

print publish_module(name,
                     request=request,
                     response=response,
                     )

The script always returns a 404 response (not found) for 
sentinel:8080/folder.

What am I doing wrong?

Andreas



More information about the Zope mailing list