[SPAM] Re: [mod_python] Need Help ...Please!!!

Nicholas Milkovits nmilkovits at gmail.com
Thu Mar 29 14:25:01 EST 2007


nitin,

print <some html> will print to stdout

I think if you want to write html back to the requester you want to do
something like:

req.content_type = "text/html"
req.write(<some string of html>)

-nick

On 3/29/07, mod_python-request at modpython.org
<mod_python-request at modpython.org> wrote:
> Send Mod_python mailing list submissions to
>         mod_python at modpython.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mailman.modpython.org/mailman/listinfo/mod_python
> or, via email, send a message with subject or body 'help' to
>         mod_python-request at modpython.org
>
> You can reach the person managing the list at
>         mod_python-owner at modpython.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Mod_python digest..."
>
>
> Today's Topics:
>
>    1. Re: Hello (Graham Dumpleton)
>    2. Re: connection to host server broken (Graham Dumpleton)
>    3. Need Help ...Please!!! (nitin chandra)
>    4. RE: how to use Mysql on mod_python+apache? (Martijn Moeling)
>    5. Textbooks on psp programming? (Mark)
>    6. RE: session variable value (partially) dissapearing
>       (Martijn Moeling)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 29 Mar 2007 08:05:19 +1000
> From: "Graham Dumpleton" <graham.dumpleton at gmail.com>
> Subject: [mod_python] Re: Hello
> To: " Idoia Villaci?n Z?rate " <fidita48 at hotmail.com>
> Cc: mod_python at modpython.org
> Message-ID:
>         <88e286470703281505q2a9a6a34g2c3d16365c9503a1 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 29/03/07, Idoia Villacián Zárate <fidita48 at hotmail.com> wrote:
> >
> >
> >
> > Hello:
> >
> > I've looked the web you gave me, but I can't see anywhere how to change the
> > configuration of my apache to choose the mod_python script instead of the
> > CGI script. I also think that I have the lastest version od the mod_python
> > (3.3.1). I'll be gratefull if you could help me or tell me how to resolve
> > the problem.
>
> Please use reply-all when responding, thus keeping the conversation on
> the mod_python mailing list.
>
> As to your problem, if you cannot ascertain from that document which
> bits referred to how to configure Apache, then you need to perhaps
> learn more about how to configure Apache and the language it uses to
> refer to its directives and where to put them. On that I can only
> suggest you go to the Apache documentation and start reading. Some
> starting points are:
>
>   http://httpd.apache.org/docs/2.2/
>   http://httpd.apache.org/docs/2.2/configuring.html
>   http://httpd.apache.org/docs/2.2/sections.html
>   http://httpd.apache.org/docs/2.2/howto/cgi.html
>
> Also refer to the mod_python documentation to learn about its own
> specific configuration directives:
>
>   http://www.modpython.org/live/current/doc-html/inst-testing.html
>   http://www.modpython.org/live/current/doc-html/directives.html
>
> Beyond that we can't really help since you haven't actually included
> in your email what snippet of Apache configuration you think you are
> using to enable mod_python use in the first place. Thus, cannot say
> how it is wrong, or how it is conflicting with existing CGI
> configuration in your setup.
>
> The only thing we can tell you as we already have, is that error would
> generally arise when your script is run as a CGI program and not
> through mod_python. This is because the _apache module is a special
> module not available from command line Python and is only available
> when code is running inside of mod_python. That the module cannot be
> found indicates the code isn't running under mod_python.
>
> Oh, and please do not go sending your complete Apache configuration,
> just those bits which would be relevant, such as the mod_python and
> CGI sections.
>
> Graham
>
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 29 Mar 2007 12:05:37 +1000
> From: "Graham Dumpleton" <graham.dumpleton at gmail.com>
> Subject: Re: [mod_python] connection to host server broken
> To: "sikander hayat" <hayat221 at yahoo.com>
> Cc: Mod_python at modpython.org, Jim Gallacher <jpg at jgassociates.ca>
> Message-ID:
>         <88e286470703281905t5e864819gc1f1f64f8d832fed at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 28/03/07, sikander hayat <hayat221 at yahoo.com> wrote:
> > Hi,
> >
> > I tried the testhandler and then looked at the first 100 entries of the
> > error log and there it was...the segmentation fault.
>
> Yes, but what did the first 100 entries say?
>
> What are you actually saying here? Are you saying you triggered 100
> requests of the handler and only then did your handler crash Apache,
> or that there was simply 100 unrelated entries that preceded the crash
> point, where the crash was the outcome of the very first request? I
> would help that you actually posted from the log the entry for the
> crash and anything just prior to that point that seems relevant.
>
> It would also help that you post the snippet of your Apache
> configuration so we can see how you have set it up to run mod_python
> and what handler you might be triggering, whether it be your own or
> one from mod_python such as publisher.
>
> > The code that i tried
> > is as follows:
> >
> > from mod_python import apache
> >
> > import module2
>
> But what is in module2. Did you put log statements in module2 so as to
> see what was run in there when import was done and how far it got.?
>
> > apache.log_error(__file__ + " #3")
> >
> > def handler(req):
> >
> >         req.content_type = "text/plain"
> >         req.write("Hello World!")
> >
> >         return apache.OK
> >
> > Thanks
> > Sikander
> >
> > Jim Gallacher <jpg at jgassociates.ca> wrote:
> >  sikander hayat wrote:
> > > Hi,
> > >
> > > Thanks for your help. Just wanted to point out that, out of frustation, i
> > installed mod_python 3.2.10 and discarded mod_python 3.3.1 and magically it
> > all works fine !!!
> > >
> > > What I would like to conclude from this is, that there might be some
> > dependency in 3.3.1 that caused havoc...(atleast for me). As pointed out
> > previously, 3.3.1 constantly kept on giving the following errors:
> > >
> > > child pid 28468 exit signal Segmentation fault (11)
> > > [Tue Mar 27 17:26:14 2007] [notice] child pid 28469 exit signal
> > Segmentation fault (11)
> > > [Tue Mar 27 17:26:40 2007] [error] [client 134.96.24.83] File does not
> > exist: /opt/lampp/htdocs/favicon.ico
> > > [Tue Mar 27 17:29:21 2007] [error] [client 134.96.24.83] File does not
> > exist: /opt/lampp/htdocs/favicon.ico
> > >
> > >
> > > Why this segmentation error with 3.3.1
> >
> > Obviously we'd like to sort out why 3.3.1 is segfaulting. Did you try
> > Graham's suggestion of doing:
> >
> >  PythonHandler mod_python.testhandler
> >
> > and still get a segfault? If not, can you either try it, or share the
> > contents of you index.py file that caused the problem?
> >
> > > and also, i had nothing to do with this favicon.ico. I do not have this
> > icon and
> >  > do not intend to make one. Why and which process needs this icon...
> > *wondering*
> >
> > This has nothing to do with mod_python. It's your browser that is
> > requesting favicon.ico. You don't have one and apache logs that fact,
> > and is standard behaviour for a missing file. If you don't intend to
> > create one you better get used to having your error logs clogged with
> > this message, as I believe some (all?) modern browsers automatically
> > request it.
> >
> > Jim
> >
> > > Thanks,
> > > Sikander
> > >
> > >
> > > Graham Dumpleton wrote: On 26/03/07, sikander hayat wrote:
> > >> Hi,
> > >>
> > >> I am using suse 10.1, Apache 2.2.4, python 2.5 and mod_python 3.3.1.
> > >>
> > >> The error log is as follows:
> > >> [Mon Mar 26 10:16:48 2007] [warn] RSA server certificate is a CA
> > certificate
> > >> (BasicConstraints: CA == TRUE !?)
> > >> [Mon Mar 26 10:16:48 2007] [warn] RSA server certificate CommonName (CN)
> > >> `localhost' does NOT match server name!?
> > >> [Mon Mar 26 10:16:48 2007] [notice] mod_python: Creating 8 session
> > mutexes
> > >> based on 256 max processes and 0 max threads.
> > >> [Mon Mar 26 10:16:48 2007] [notice] mod_python: using mutex_directory
> > /tmp
> > >> [Mon Mar 26 10:16:48 2007] [notice] Apache/2.2.4 (Unix) DAV/2
> > mod_ssl/2.2.4
> > >> OpenSSL/0.9.8d mod_python/3.3.1 Python/2.5 PHP/5.2.1
> > >> mod_apreq2-20051231/2.5.7 m
> > >> od_perl/2.0.2 Perl/v5.8.7 configured -- resuming normal operations
> > >> [Mon Mar 26 10:17:04 2007] [error] [client 134.96.24.83] File does not
> > >> exist: /opt/lampp/htdocs/favicon.ico
> > >> [Mon Mar 26 10:17:35 2007] [notice] mod_python (pid=3230,
> > >> interpreter='localhost'): Importing module
> > >> '/opt/lampp/htdocs/parkweb/index.py'
> > >> [Mon Mar 26 10:17:35 2007] [notice] mod_python (pid=3231,
> > >> interpreter='localhost'): Importing module
> > >> '/opt/lampp/htdocs/parkweb/index.py'
> > >> [Mon Mar 26 10:17:36 2007] [notice] child pid 3230 exit signal
> > Segmentation
> > >> fault (11)
> > >> [Mon Mar 26 10:17:36 2007] [notice] child pid 3231 exit signal
> > Segmentation
> > >> fault (11)
> > >>
> > >> I have recently upgraded to python 2.5. So, to say, i have 2 versions of
> > >> python on my system. Will try to remove the older one and try again.
> > >
> > > To confirm whether that is necessary, set:
> > >
> > > PythonHandler mod_python.testhandler
> > >
> > > In the output from that just verify that the sys.path information is
> > > correct for the version of Python you expect to use. From the above
> > > log entries there probably isn't a problem with versions as mod_python
> > > will actually log some warnings if it finds a different version of
> > > Python than what it was compiled with and that isn't in the log
> > > entries.
> > >
> > >> ****Why is it loading the module twice ...is that normal ???
> > >
> > > Note how the 'pid' is different for each. This means that there were
> > > two requests and that they so happened to be handled by different
> > > Apache child processes.
> > >
> > >> Kindly let me know if something rings a bell.
> > >
> > > Since you are using Python 2.5, it should not be the expat version
> > > problem as Python 2.5 is supposed to change things to avoid that one.
> > > I would though still suspect that it is some versioning problem with
> > > shared libraries. For example, if your web application uses some sort
> > > of database and you also have PHP loaded and it is using some
> > > different version of the database client library. This sort of
> > > mismatch can cause a crash as one library will take precedence over
> > > the other and if they are not compatible it can crash.
> > >
> > > What you may need to do is start adding debug into your code and the
> > > framework it uses such that you output a log message before and after
> > > every module import. For example:
> > >
> > > from mod_python import apache
> > >
> > > apache.log_error(__file__ + " #1")
> > > import pyexpat
> > > apache.log_error(__file__ + " #2")
> > > import module2
> > > apache.log_error(__file__ + " #3")
> > >
> > > See how many of the messages come out in the Apache error log and slow
> > > narrow it down to a specific module being importer causing the crash.
> > >
> > > If the module imports aren't the problem but something in handler
> > > itself, do something similar, logging messages to the Apache log until
> > > you find exactly what call causes it.
> > >
> > > Graham
> > >
> > >> Thanks,
> > >>
> > >>
> > >> Graham Dumpleton wrote:
> > >> On 24/03/07, Jim Gallacher wrote:
> > >>> sikander hayat wrote:
> > >>>> Hi all,
> > >>>>
> > >>>> My apache webserver on linux recently broke down, so i reinstalled it,
> > >> along with mod_python. Having made the necessary changes in the conf file
> > of
> > >> apache, i tried some of the simple tests, such as mptest, but i keep on
> > >> getting the following error.
> > >>>> Connection to host server ... lost.
> > >>>>
> > >>>> Why is that, is it because of python or some apache setting.
> > >>> Or network problems?
> > >>>
> > >>> What do you find in your apache logs?
> > >> The Apache error log would be a good start, as it looks to me like
> > >> your Apache child processes are crashing. You may find errors about
> > >> segmentation violations or similar in the logs. If you do, check that
> > >> the version of mod_python you are using is the correct one for the
> > >> version of Python and Apache you are using. Having multiple versions
> > >> of Python installed can also cause issues.
> > >>
> > >> BTW, are you using precompiled packages or compiling everything from
> > >> source code? What operating system are you using?
> > >>
> > >> Graham
> > >>
> > >>
> > >>
> > >> ________________________________
> > >> Sucker-punch spam with award-winning protection.
> > >> Try the free Yahoo! Mail Beta.
> > >>
> > >>
> > >
> > >
> > >
> > > ---------------------------------
> > > The fish are biting.
> > > Get more visitors on your site using Yahoo! Search Marketing.
> > >
> > >
> > >
> > ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > Mod_python mailing list
> > > Mod_python at modpython.org
> > > http://mailman.modpython.org/mailman/listinfo/mod_python
> >
> >
> >
> >
> >  ________________________________
> > Expecting? Get great news right away with email Auto-Check.
> > Try the Yahoo! Mail Beta.
> >
> >
>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 29 Mar 2007 17:24:38 +0530
> From: "nitin chandra" <nitinchandra1 at gmail.com>
> Subject: [mod_python] Need Help ...Please!!!
> To: mod_python at modpython.org
> Message-ID:
>         <965122bf0703290454x1fd3ed25y9deda0f1b4f7d9f9 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi Everyone!
>
> I need some help here.
>
> I have a WinXP laptop, installed with Python2.4, Apache 2.0.59,
> mod_python-3.2.8.win32-py2.4.exe,
> psycopg2-2.0.5.1.win32-py2.4-pg8.2.0-release.exe, PostgreSQL 8.2.
>
> Now i have created a DB as "nitin" and a user "nitin", further i
> created 13 more tables within the DB. One of the
> tables is named as "area". This, "area", table has 11 fields. Two
> fields are left blank as they will
> be entered through a web interface.
>
> So i am trying to read the complete row and display the existing data
> in the table. The display of the data is to be done in various forms
> fields over the Web-interface / html(or CSS). Lastly, Enter data in
> blank form fields and update the table.
>
>
> I am writing a 'area.py' script for the above.
>
> ======================
>
> from mod_python import apache
> import sys, psycopg
>
> conn = psycopg.connect("dbname=nitin user=nitin passwd=" "")
>
> curs = conn.cursor()
>
>
>
> <head><title>Owners' Details Entered</title></head>
> <body bgcolor="#87CEFA">
> <table align=center border=2 cellpadding=6>
>
>
> curs.execute("SELECT * FROM area")
> rows = curs.fetchall()
>
> print <tr><td>rows</td></tr>
>
>
> </table>
> </body>
> </head>
>
> ===================
>
> And it does not work. When I load the page in IE, HTML works but the
> rest of the code is displayed as it is,i.e. as text.
>
> Are there any samples available on the net where i can look at.
>
> Please guide.
>
> Thanks
> Reg
> Nitin
>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 29 Mar 2007 13:58:55 +0200
> From: "Martijn Moeling" <martijn at xs4us.nu>
> Subject: RE: [mod_python] how to use Mysql on mod_python+apache?
> To: <mod_python at modpython.org>
> Message-ID:
>         <B6C73A5E30565245BB6D32B5F5DF7A52120333 at sense.emmastraat.pijnacker>
> Content-Type: text/plain;       charset="US-ASCII"
>
> I don't see the fuzz about mysql either. It is rock solid and I use(d)
> it a lot in production environment, together with mysqldb and mod
> python.
>
> When using it with mod python there are a few things to be aware of.
>
> First make sure the connection and cursor objects are not created
> globally I use:
>
>
> Def handler(req):
> ..
> ..
>         req.db = MySQLdb.connect( host=Chost, user=Cuser,
> passwd=Cpasswd, db=Cdb, use_unicode=True, charset='utf8')
>         req.cursor = req.db.cursor()
>
> #next I close the database in a fixup handler
>
> req.register_cleanup(closedb,req)
>
> ...
>
> And the closedb function
>
> def closedb(req):
>     try:
>         req.cursor.close()
>         req.cursor=None
>         req.db.close()
>         req.db = None
>     except:
>         pass
>
> with this method of using mysqldb, the database connection is closed
> properly, even if the handler code runs into an error, if not and an
> error occurs and the connection is kept by MySQL and at the end it will
> run out of resources (and/or memory whatever comes first).
>
> And to the off topic part:
> People seem to blame software when it behaves as designed and they don't
> read manuals and/or know background theory, please keep non mod_python
> issues out of this list and respect choices made by other people, even
> if you think it is a bad one. The question was "How can I use Mysql with
> MP".
>
> To explain this further, I see people asking questions about MP running
> on windows, personally I have the opinion that Microsoft sells crap but
> that is since I know about unixes, OpenVMS, MVS etc. etc. and windows.
> But I'll never suggest : trow out windows and install xxxxx since the
> other person might be more familiar with windows, that is the tool of
> choice for him.
>
> Getting started with MP has a steep learning curve, not because MP is
> difficult to use, but since a lot of different technologies and
> standards apply (file protection, apache, mime types, character sets,
> HTML, javascript, xml, htttp (headers!), browser incompatibility,
> python, etc, etc.
> I have over 30 years of professional experience and I had a lot to learn
> when I started with MP.
>
> I am thinking of publishing parts of my system on a dedicated MP
> examples website, since I solved a lot of technology difficulties
> (uploading pictures, resizing pictures, pictures stored in Mysql,
> characterset conversion, a simple spiderbot, a simple templating system
> etc.
>
> MP beats a lot of other similar tools but in my eyes there is a lack of
> proper simple to understand examples for so called newbie's that are
> well documented
>
> Martijn Moeling
>
> -----Oorspronkelijk bericht-----
> Van: mod_python-bounces at modpython.org
> [mailto:mod_python-bounces at modpython.org] Namens Mike Looijmans
> Verzonden: Wednesday, March 28, 2007 12:02 PM
> Aan: mod_python at modpython.org
> Onderwerp: Re: [mod_python] how to use Mysql on mod_python+apache?
>
> This thread is going way of topic, but I'd really hate to see people
> being turned away from MySQL as
> a DB engine just because of the inaccuracies posted here.
>
> I have several years of experience with many DBMSs, including Informix,
> Oracle, MS SQLServer,
> Postgress, MySQL and several others. MySQL is my favorite for (non-.NET)
> web applications, because
> of its scalability, performance, reliability, low maintenance and ease
> of use.
>
> There are many DBMSs, each with their own pecularities, and none of them
> I would consider "bad" (or
> even "evil"). Which DBMS to chose for a particular task seems to become
> a matter of personal taste
> more everyday, because the more general offerings, like the ones I
> mentioned, all provide the same
> rich feature set (e.g. transactions, subqueries, stored procedures,
> outer joins). While I would not
> hesitate to recommend in favor of some of the databases I am familiar
> with, there is not one that i
> would ever tell people to "avoid at all cost". Even FoxPro has its uses.
>
> > Sorry, but accepting invalid input without error, truncating overly
> long
> > input and clipping overflowed numbers are not "quirks".
>
> I agree so far.
>
> >  They are serious data integrity issues.
>
> I disagree here, because the issues you mentioned are configuration
> settings in MySQL. You can
> change the behaviour of the server in the config file. It is unfortunate
> that the default settings
> are not the ANSI ones. But you can make the MySQL DB comply to the more
> general standard of issuing
> an error on overflow and other forms of invalid input.
>
> I suggest reading some documentation before proceeding on the subject.
>
> > That's fine.  At least you aren't really using MySQL in production :-)
>
> I have. On my previous assignment, the customer would loose about $10k
> per hour in lost machine time
> only (not even taking the engineers cost into account) if the MySQL
> database went offline. It did go
> offline once in that three year period i worked there - the power went
> down, the UPS failed and the
> operating system (Solaris) died a horrible dead along with the hard
> drive. When the power came up, I
> had its replacement up and running in about ten minutes, and no data was
> lost.
>
>
> --
> Mike Looijmans
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>
>
> ------------------------------
>
> Message: 5
> Date: Thu, 29 Mar 2007 14:04:48 +0200
> From: Mark <mctse at vodamail.co.za>
> Subject: [mod_python] Textbooks on psp programming?
> To: Graham Dumpleton <graham.dumpleton at gmail.com>,
>         Mod_python at modpython.org
> Message-ID: <460BAB60.7090107 at vodamail.co.za>
> Content-Type: text/plain; charset=ISO-8859-1
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dear mod_python guru.
>
> I taught myself how to program with php and would love to learn how to
> use mod_python.  I learned php from an excellent book called php4 for
> beginners (after all that's exactly what I was - and am as regards
> python -) and would greatly appreciate it if you could refer me to an
> equivalent book on psp programming.
>
>
> Kindest regards
>
>
>
> Mark Coetsee
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
>
> iD8DBQFGC6tgLzNh63IR8ssRArusAJ9T9THiyvbu8ZiJtCKuejD+SiiQLQCgm3uG
> RlvXnPYgO94PtrCmvus07VI=
> =V/8D
> -----END PGP SIGNATURE-----
>
>
>
> ------------------------------
>
> Message: 6
> Date: Thu, 29 Mar 2007 14:12:11 +0200
> From: "Martijn Moeling" <martijn at xs4us.nu>
> Subject: RE: [mod_python] session variable value (partially)
>         dissapearing
> To: "Jim Gallacher" <jpg at jgassociates.ca>,      "Detmar Meurers"
>         <dm at ling.ohio-state.edu>
> Cc: mod_python at modpython.org, Graham Dumpleton
>         <graham.dumpleton at gmail.com>
> Message-ID:
>         <B6C73A5E30565245BB6D32B5F5DF7A52120334 at sense.emmastraat.pijnacker>
> Content-Type: text/plain;       charset="US-ASCII"
>
> Are you properly saving the session at every request?
> Like:
>
> # Created session like this:
> # req.session = Session.Session(req)
>
> Req.session.save()
>
> Martijn
>
> -----Oorspronkelijk bericht-----
> Van: mod_python-bounces at modpython.org
> [mailto:mod_python-bounces at modpython.org] Namens Jim Gallacher
> Verzonden: Wednesday, March 28, 2007 3:00 AM
> Aan: Detmar Meurers
> CC: mod_python at modpython.org; Graham Dumpleton
> Onderwerp: Re: [mod_python] session variable value (partially)
> dissapearing
>
> Detmar Meurers wrote:
> > Hi Graham,
> >
> > Thanks for the very quick reply.
> >
> > The page showing the problem actually is using the publisher handler
> > (so no special exception handling etc.)
> >
> > I tried the FileSession and the problem occurs there too - and I'm
> > not doing any calling of unlock().
> >
> > I am calling req.session.save() - one question about that though:
> > Can it possibly cause problems when calling the save() several times
> > when handling one request?
>
> It shouldn't matter. The session store is locked so only one request can
>
> read or write at a time. This is the case even if you have session
> locking turned off, or unlock the session manually.
>
> Jim
> _______________________________________________
> 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
>
>
> End of Mod_python Digest, Vol 48, Issue 37
> ******************************************
>



More information about the Mod_python mailing list