Graham Dumpleton
graham.dumpleton at gmail.com
Fri Dec 5 23:12:17 EST 2008
2008/12/6 Reuben A Christie <christie at knewco.com>: > its version 3.3.1 i removed send_http_header() call, still n o difference Work out then under what conditions the follow code would generate the error you are seeing, where content_type would be passed as argument to function. static content_type *analyze_ct(request_rec *r, const char *s) { const char *cp, *mp; char *attribute, *value; int quoted = 0; server_rec * ss = r->server; apr_pool_t * p = r->pool; content_type *ctp; param *pp, *npp; /* initialize ctp */ ctp = (content_type *)apr_palloc(p, sizeof(content_type)); ctp->type = NULL; ctp->subtype = NULL; ctp->param = NULL; mp = s; /* getting a type */ cp = mp; while (apr_isspace(*cp)) { cp++; } if (!*cp) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "mod_mime: analyze_ct: cannot get media type from '%s'", (const char *) mp); return (NULL); } ctp->type = cp; do { cp++; } while (*cp && (*cp != '/') && !apr_isspace(*cp) && (*cp != ';')); if (!*cp || (*cp == ';')) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "Cannot get media type from '%s'", (const char *) mp); return (NULL); } I don't have the time to work it out myself. Graham > Graham Dumpleton wrote: >> >> 2008/12/6 Reuben A Christie <christie at knewco.com>: >> >>> >>> this is how my apache config looks like >>> <Directory /usr/local/apache/htdocs/linker_python > >>> Options ExecCGI -MultiViews FollowSymLinks >>> AllowOverride All >>> Order allow,deny >>> allow from all >>> AddHandler mod_python .py >>> PythonHandler launch >>> PythonDebug On >>> AddType text/plain >>> </Directory> >>> >>> and in the code i do following >>> >>> req.send_http_header() >>> req.content_type = 'text/xml' (it does not matter what do i set content >>> type, even if i change this to text/plain or text/html does not make any >>> differece) >>> req.write("<response>hello world</response>") >>> >> >> Which version of mod_python are you using? >> >> Calling req.send_http_header() is only needed for mod_python 2.7.X and >> older. Even then, it should go after setting req.content_type. >> >> If still using mod_python 2.7.X, then upgrade. If you can't because >> you are using Apache 1.3, then consider using mod_wsgi instead and >> write your web application to WSGI API, using one of the many >> toolkits/frameworks out there for WSGI. >> >> Graham >> >> >>> >>> Graham Dumpleton wrote: >>> >>>> >>>> 2008/12/6 Reuben A Christie <christie at knewco.com>: >>>> >>>> >>>>> >>>>> In the python script itself, i set the content type to text/plain , I >>>>> have >>>>> not set any AddType directive in apache config >>>>> >>>>> >>>> >>>> Please post code snippet showing how this is being done and what >>>> handler you are using? Ie., custom handler, mod_python.publisher etc. >>>> >>>> What AddHandler directives do you have set in Apache configuration? >>>> >>>> Have you setup any output filters in Apache, ie., AddOutputFilter* >>>> directives? >>>> >>>> Graham >>>> >>>> >>>> >>>>> >>>>> Graham Dumpleton wrote: >>>>> >>>>> >>>>>> >>>>>> 2008/12/5 Reuben A Christie <christie at knewco.com>: >>>>>> >>>>>> >>>>>> >>>>>>> >>>>>>> thanks alot graham. I was able to import the modules the way you >>>>>>> showed. >>>>>>> its >>>>>>> little intriguing but I think I ll find a better way by combining >>>>>>> them >>>>>>> into >>>>>>> one __init__.py hopefully that will work >>>>>>> one more question, I keep seeing this warning message on apache log >>>>>>> [warn] Cannot get media type from 'mod_python' >>>>>>> its not causing any issue but I really don't understand why is it >>>>>>> appearing >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> What is the content type you are returning or have setup using AddType >>>>>> directives? It appears it may be malformed. The message is mod_mime >>>>>> complaining about it. >>>>>> >>>>>> Graham >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> >>>>>>> Graham Dumpleton wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> 2008/12/3 Reuben A Christie <christie at knewco.com>: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> Hi all, I am pretty novice user of mod_python. and there is an >>>>>>>>> issue >>>>>>>>> that >>>>>>>>> I >>>>>>>>> am experiencing with mod_python scripts for past 2 days that I am >>>>>>>>> not >>>>>>>>> able >>>>>>>>> to solve. >>>>>>>>> >>>>>>>>> my directory structure is as following, >>>>>>>>> >>>>>>>>> DocumentRoot : /usr/local/apache2/htdocs/ >>>>>>>>> i have a directory structure for mod_python scripts under >>>>>>>>> DocumentRoot >>>>>>>>> is, >>>>>>>>> >>>>>>>>> launch.py >>>>>>>>> python_test/p1/test1 >>>>>>>>> python_test/p2/test2 >>>>>>>>> >>>>>>>>> in apache config, i have added following >>>>>>>>> >>>>>>>>> <Directory /usr/local/apache/htdocs/python_test > >>>>>>>>> AllowOverride All >>>>>>>>> Order allow,deny >>>>>>>>> allow from all AddHandler mod_python .py >>>>>>>>> PythonHandler launch >>>>>>>>> PythonDebug On >>>>>>>>> </Directory> >>>>>>>>> >>>>>>>>> and launch.py looks like this, >>>>>>>>> >>>>>>>>> import os.path >>>>>>>>> from mod_python import apache, Session, util >>>>>>>>> >>>>>>>>> def handler(req): >>>>>>>>> request = os.path.splitext(os.path.basename( req.uri ))[0] >>>>>>>>> req.content_type = 'text/plain' >>>>>>>>> req.send_http_header() >>>>>>>>> >>>>>>>>> status = apache.OK >>>>>>>>> if request != None: >>>>>>>>> mod = __import__(request) >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> This is the wrong way of going about it. See below. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> if request == "test1": >>>>>>>>> status = mod.handler(req) >>>>>>>>> return status >>>>>>>>> basically this script should act as gateway for rest of the >>>>>>>>> python scripts . >>>>>>>>> >>>>>>>>> when I test it with, http://localhost/python_test/test1.py it does >>>>>>>>> not >>>>>>>>> work >>>>>>>>> (i get Not found message) and if I do >>>>>>>>> http://localhost/python_test/p1 >>>>>>>>> i >>>>>>>>> get >>>>>>>>> the source code of the script appear. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> For configuration as written, the launch.py file is in wrong >>>>>>>> location. >>>>>>>> >>>>>>>> First off suggest that launch.py not be in htdocs as then someone >>>>>>>> can >>>>>>>> download source code to your handler. >>>>>>>> >>>>>>>> Presuming you are using mod_python 3.3.1 (if not then upgrade), move >>>>>>>> the launch.py file elsewhere and then change configuration to use: >>>>>>>> >>>>>>>> PythonHandler /some/path/launch.py >>>>>>>> >>>>>>>> Where path is location of launch.py outside of htdocs. >>>>>>>> >>>>>>>> Also don't use __import__. You are better off using import_module() >>>>>>>> from mod_python. That way you can just supply a path to file to >>>>>>>> import >>>>>>>> and not have to worry about PythonPath and lots of other module >>>>>>>> madness. See: >>>>>>>> >>>>>>>> http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html >>>>>>>> >>>>>>>> Graham >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Mod_python mailing list >>>>>>> Mod_python at modpython.org >>>>>>> http://mailman.modpython.org/mailman/listinfo/mod_python >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> Mod_python mailing list >>>>> Mod_python at modpython.org >>>>> http://mailman.modpython.org/mailman/listinfo/mod_python >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> >>> _______________________________________________ >>> Mod_python mailing list >>> Mod_python at modpython.org >>> http://mailman.modpython.org/mailman/listinfo/mod_python >>> >>> >>> >> >> >> > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python > >
|