[mod_python] Mod-Python Help

Ethan Toan Ton ethanton at ethanton.com
Mon Sep 4 20:03:39 EDT 2006


Gavin/Nicolas,

Thanks for your help.  It turns out the problem was the "return
apache.OK".  I was getting that extra 0 at the end and could not figure
out why.  Thanks for the prompt replies.  I appreciate all the help.

Ethan


> Ooops sorry... I should learn to read questions better than that.
>
> Have you tried to curl or wget the page to see the result ? Is this really
> valid XML ?
>
> What have you implemented ? A handler or a published module, i.e. do you
> use
> the mod_python.publisher handler ? If this is the case, then since you are
> returning apache.OK instead of returning the document itself, you may get
> an
> additional '0' (the value of apache.OK) at the end of the response, which
> may bother the XML parser. But a much better approach is to use
> send_file()
> and return None (or implement a handler).
>
> Another problem might be with the charset encoding of the document. Is it
> specified in the XML header ? If not, then a different default charset
> encoding between the server and the client platforms may cause the parsing
> to fail.
>
> Note that you should be able to add an error handling callback on the
> XMLHttpRequest objec to have more info on the problem.
>
> Regards,
> Nicolas
>
> 2006/9/4, Ethan Toan Ton <tton at stanfordalumni.org>:
>>
>> Nicolas,
>>
>> The path isn't the problem.  The handler reads the file fine.  But when
>> it
>> outputs to the requester, the formatting is done incorrectly so that it
>> can't
>> be parsed.
>>
>> Ethan
>>
>>
>> ------ Original Message ------
>> Received: 11:25 AM PDT, 09/04/2006
>> From: "Nicolas Lehuen" <nicolas at lehuen.com>
>> To: "Ethan Toan Ton" <ethanton at ethanton.com>Cc: mod_python at modpython.org
>> Subject: Re: [mod_python] Mod-Python Help
>>
>> Hi,
>>
>> You have to provide absolute paths when accessing local file. This is
>> because the cwd is always /.
>>
>> I you want to built paths relative to the script you are writing, you
>> can
>> use the __FILE__ meta variable :
>>
>> LOCAL_FILE = os.path.join(os.path.dirname(__FILE__),'myfile.txt')
>>
>> Regards,
>> Nicolas
>>
>> 2006/9/4, Ethan Toan Ton <ethanton at ethanton.com>:
>> >
>> > Hi,
>> >
>> > I'm not sure if this is the correct forum to be asking for help with
>> > Mod-Python, but I figure I'd give it a shot.  I was wondering if
>> anyone
>> > had experience using a Mod-Python request handler to answer a
>> javascript
>> > xmlhttprequest().
>> >
>> > When my javascript program does a request on the xml file directly,
>> all
>> of
>> > the javascript parsing of the xml works fine.  However, when I try to
>> call
>> > the request handler and get it to read the file in and return the
>> request,
>> > the javascript can't parse the xml.  Here's the code:
>> >
>> >
>> > LOCAL_FILE = 'htdocs/ethan/info.xml';
>> >
>> > def get_request(req):
>> >         if req.method == 'GET':
>> >                 file = open(LOCAL_FILE, 'r')
>> >                 req.content_type = "application/xml"
>> >                 req.write(file.read())
>> >         return apache.OK
>> >
>> > The same data is sent, but I'm not sure if there is a formatting
>> problem
>> > here.  I'm assuming that's the problem, but I'm at a loss as to the
>> > solution.  req.sendfile(LOCAL_FILE) does not work either.
>> >
>> > Any help would be greatly appreciated.
>> >
>> > Ethan
>> >
>> >
>> > _______________________________________________
>> > Mod_python mailing list
>> > Mod_python at modpython.org
>> > http://mailman.modpython.org/mailman/listinfo/mod_python
>> >
>>
>>
>>
>>
>> ____________________________________________________________________
>>
>>
>>
>




More information about the Mod_python mailing list