#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    3
    Rep Power
    0

    mod_python throws 'mp_request' object has no attribute error. Why?


    I have an app that runs fine under python 2.3.4. When I run it under mod_python I get the following:


    Mod_python error: "PythonHandler dispatcher"

    Traceback (most recent call last):

    File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
    result = object(req)

    File "/var/www/python/dispatcher.py", line 49, in handler
    return handlerfunc(req)

    File "/var/www/python/conversionList.py", line 22, in handler
    ConversionList(req, 'conversionList.pdf', 2005)

    File "/var/www/python/conversionList.py", line 47, in __init__
    self.createReport(req, self, args, year)

    AttributeError: 'mp_request' object has no attribute 'createReport'


    What could I be missing or have not done correctly? Here is the code in question:

    Code:
    from mod_python import apache
    from reportlab.pdfgen import canvas
    import time, os, sys
    
    from optik import OptionParser
    import MySQLdb
    import MySQLdb.cursors
    
    try:
        import _rl_accel
            ACCEL = 1
        except ImportError:
            ACCEL = 0
    
    from reportlab.lib.units import inch, cm
    from reportlab.lib.pagesizes import LETTER
    
    def handler(req):
        req.content_type = "text/html"
        if req.header_only:
            return apache.OK
        ConversionList(req, 'conversionList.pdf', 2005)
        return apache.OK
    
    class ConversionList:
        top_margin = LETTER[1]
        bottom_margin = inch
        left_margin = inch/2
        right_margin = LETTER[0] - inch
        frame_width = right_margin - left_margin
        newPageFlag = 0
        HeaderNeeded = 0
        PageHeader = 1
        CurrentGroup = ''
        row = ''
        GREENBAR = (14.875*inch, 11*inch)
        BILLING = (9.7*inch, 5.5*inch)
    
        def __init__(req, self, args, year):
            self.createReport(req, self, args, year)
    
        def createReport(req, self, args, year):
            started = time.time()
            self.a = time
            self.b = self.a.localtime()
    Thanks,
    Mel
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    3
    Rep Power
    0
    Fixed the problem on my own.

    Changed it to keep the __init__ function from calling createReport. It now looks like this:

    Code:
    def handler(req):
        req.content_type = "text/html"
        if req.header_only:
            return apache.OK
        a = ConversionList(req)
        a.test(req, 'conversionList.pdf', 2005)
        return apache.OK
    
    class ConversionList:
    
        def __init__(self, req):
    	self.top_margin = LETTER[1]
    	self.bottom_margin = inch
    	self.left_margin = inch/2
    	self.right_margin = LETTER[0] - inch
    	self.frame_width = self.right_margin - self.left_margin
    	self.newPageFlag = 0
    	self.HeaderNeeded = 0
    	self.PageHeader = 1
    	self.CurrentGroup = ''
    	self.row = ''
    	self.GREENBAR = (14.875*inch, 11*inch)
    	self.BILLING = (9.7*inch, 5.5*inch)
    
        def test(self, req, args, year):
            req.write("Made it!")
            self.createReport(req, args, year)
    
        def createReport(self, req, args, year):
            started = time.time()
            self.a = time
    Mel

IMN logo majestic logo threadwatch logo seochat tools logo