Problems with class

4 views
Skip to first unread message

miso

unread,
Jan 4, 2011, 1:41:31 PM1/4/11
to modwsgi
Hi everyone... I am really new in python and mod_wsgi.

I have a simple class:

class connector(object):
def __init__(self):
self.one = 'one var'
self.two = 'two var'

def anymethod(self):
return 'i am here...'


my problem is that when I import a class, python does not find any
attribute or method in my class
This only happens when I import the class from my WSGI application:

#I add my path directory to sys.path
path = os.path.dirname(__file__)

if path not in sys.path:
sys.path.insert(0, path)

from com.example.core.bbdd import connector

def application(environ, start_response):

temp = connector()
output = temp.anymethod()

status = '200 OK'
response_headers = [('Content-type', 'text/plain'),('Content-
Length', str(len(output)))]
start_response(status, response_headers)
return [output]

i have this error in the apache log file: ( this error is)

[Tue Jan 04 15:04:20 2011] [info] [client 192.168.254.2] mod_wsgi
(pid=2731, process='', application='tours.in|'): Reloading WSGI script
'/var/www/sites/mypage/app/handler.wsgi'
[Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2] mod_wsgi
(pid=2731): Exception occurred processing WSGI script '/var/www/sites/
mypage/app/handler.wsgi'
[Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2] Traceback
(most recent call last):
[Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2] File "/var/
www/sites/mypage/app/handler.wsgi", line 21, in application
[Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2] output =
temp.anymethod()
[Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2]
AttributeError: 'connector' object has no attribute 'anymethod'

If I load the class for the Command Line in the python console,
everything works fine, attributes and methods exist for python.

I have no idea what could be the problem. Any help would be
appreciated =)

Graham Dumpleton

unread,
Jan 4, 2011, 4:27:42 PM1/4/11
to mod...@googlegroups.com
On 5 January 2011 05:41, miso <mis...@gmail.com> wrote:
> Hi everyone... I am really new in python and mod_wsgi.
>
> I have a simple class:
>
> class connector(object):
>    def __init__(self):
>        self.one = 'one var'
>        self.two = 'two var'
>
>    def anymethod(self):
>        return 'i am here...'
>
>
> my problem is that when I import a class, python does not find any
> attribute or method in my class
> This only happens when I import the class from my WSGI application:
>
> #I add my path directory to sys.path
> path = os.path.dirname(__file__)
>
> if path not in sys.path:
>    sys.path.insert(0, path)
>
> from com.example.core.bbdd import connector
>
> def application(environ, start_response):
>
>    temp = connector()
>    output = temp.anymethod()

Change this to:

import com.example.core.bbdd
output = ''
print >> output, '__file__', com.example.core.bbdd.__file__
print >> output, 'type()', type(temp)
print >> output, 'dir()', dir(temp)

In other words, start adding some debugging code in there to
introspect stuff about the class.

The __file__ will tell you whether you are even picking up the code
file from the location you expect and then you can edit that file to
make sure it contains what you think it should.

The other stuff tells you a bit about what the variable instance is
and what methods are available.

My guess would be that you are picking up old version of code because
it hasn't installed where mod_wsgi is looking for it of Apache wasn't
restarted to pick up changes.

Worst case is that somehow you have a .pyc file next to .py file that
is newer and so older .pyc file being used.

Graham

>    status = '200 OK'
>    response_headers = [('Content-type', 'text/plain'),('Content-
> Length', str(len(output)))]
>    start_response(status, response_headers)
>    return [output]
>
> i have this error in the apache log file: ( this error is)
>
> [Tue Jan 04 15:04:20 2011] [info] [client 192.168.254.2] mod_wsgi
> (pid=2731, process='', application='tours.in|'): Reloading WSGI script
> '/var/www/sites/mypage/app/handler.wsgi'
> [Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2] mod_wsgi
> (pid=2731): Exception occurred processing WSGI script '/var/www/sites/
> mypage/app/handler.wsgi'
> [Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2] Traceback
> (most recent call last):
> [Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2]   File "/var/
> www/sites/mypage/app/handler.wsgi", line 21, in application
> [Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2]     output =
> temp.anymethod()
> [Tue Jan 04 15:04:20 2011] [error] [client 192.168.254.2]
> AttributeError: 'connector' object has no attribute 'anymethod'
>
> If I load the class for the Command Line in the python console,
> everything works fine, attributes and methods exist for python.
>
> I have no idea what could be the problem. Any help would be
> appreciated =)
>

> --
> You received this message because you are subscribed to the Google Groups "modwsgi" group.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to modwsgi+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
>
>

miso

unread,
Jan 5, 2011, 9:59:06 AM1/5/11
to mod...@googlegroups.com
Ok, really thanks..

I will see what you have told me... i am new in python, and further with the configuration of servers..
so I will revise every details

miso

unread,
Jan 5, 2011, 12:32:06 PM1/5/11
to mod...@googlegroups.com
OK, me again...

I did what you told me, and in fact when I use the command dir(connector) my methods did not appear.

1 - first I try to delete the .pyc files, but still nothing appears.
2 - second, I restarted the apache server, and then the class already had updated their methods

after making some changes in the class, I have the same problem, and only when I restart the apache server, the changes is updated

This is normal?

miso

unread,
Jan 5, 2011, 12:50:17 PM1/5/11
to mod...@googlegroups.com
Sorry, reading the mod_wsgi documentation, I see that in EMBEDDED MODE, this is a normal issue when working with normal python modules with .py extension. is needed to restart the apache server for update a module correctly
Reply all
Reply to author
Forward
0 new messages