[mod_python] Re: Is this related to not having support to upload a file?

Graham Dumpleton grahamd at dscpl.com.au
Tue Apr 4 16:27:52 EDT 2006


Instead of:

   for k in field.file.__dict__:

try:

   for k in dir(field.file):

Grahamd

On 04/04/2006, at 11:25 PM, Alberto Ruiz wrote:

> Ok I modified the publisher.py code but I got the following:
>
> Traceback (most recent call last):
>
>   File "/usr/local/lib/python2.4/site-packages/mod_python/ 
> apache.py", line 193, in Dispatch
>     result = object(req)
>
>   File "/usr/local/lib/python2.4/site-packages/mod_python/ 
> publisher.py", line 106, in handler
>     val = File(field)
>
>   File "/usr/local/lib/python2.4/site-packages/mod_python/ 
> publisher.py", line 324, in __init__
>     for k in field.file.__dict__:
>
> AttributeError: 'file' object has no attribute '__dict__'
>
>
> So __dict__ is also not supported on newer versions of Python?  It  
> doesn't make sense.   I just did the following edit:
>
> class File:
>     """ Like a file, but also has headers and filename
>     """
>
>     def __init__(self, field):
>
>         # steal all the file-like methods
>         #for m in field.file.__methods__:
>         #    self.__dict__[m] = getattr(field.file, m)
>         for k in field.file.__dict__:
>             if k[:2] != '__':
>                 v = getattr(field.file, k)
>                 if callable(v):
>                     self.__dict__[k] = v
>
>         self.headers = field.headers
>         self.filename = field.filename
>
>
> Graham Dumpleton <grahamd at dscpl.com.au> wrote: See mailing list  
> archives. There were two responses.
>
> http://www.modpython.org/pipermail/mod_python/2006-April/020756.html
> http://www.modpython.org/pipermail/mod_python/2006-April/020757.html
>
> Graham
>
> Alberto Ruiz wrote ..
> > I apologyze for sending this email again, but my server is under  
> a DDOS
> > attack and I'm not sure if this email went through. If it did can  
> somebody
> > please forward me or post the replies again. I had to subscribe  
> again
> > to the mailing list with a different account. Thanks.
> >
> > Like I mentioned in earlier threads, this code used to work in a  
> Debian
> > system, but now it doesn't work on FreeBSD with modpython 2.7.11.
> > I'm getting the following error.
> >
> > Mod_python error: "PythonHandler mod_python.publisher"
> >
> > Traceback (most recent call last):
> >
> > File "/usr/local/lib/python2.4/site-packages/mod_python/apache.py",
> > line 193, in Dispatch
> > result = object(req)
> >
> > File "/usr/local/lib/python2.4/site-packages/mod_python/ 
> publisher.py",
> > line 106, in handler
> > val = File(field)
> >
> > File "/usr/local/lib/python2.4/site-packages/mod_python/ 
> publisher.py",
> > line 322, in __init__
> > for m in field.file.__methods__:
> >
> > AttributeError: 'file' object has no attribute '__methods__'
> >
> >
> >
> > It is hard to pin point the problem, since it doesn't show where  
> in my
> > code is happening. But my guess is that it is somewhere in this code
> > snippet:
> >
> > for p in photo:
> > phpath='/data/webroot/propman/propphotos/'
> > F= open(phpath+str("tempprop"+id+"-"+p.name[-1:]+p.filename 
> [-4:]),'wb')
> > F.write(p.file.read())
> > F.flush()
> > os.system("convert "+phpath+str("tempprop"+id
> > +"-"+p.name[-1:]+p.filename[-4:])+" -resize 400x300 "+phpath
> > +""+str("prop"+id+"-"+p.name[-1:]+p.filename[-4:]))
> > com="convert "+phpath+str("tempprop"+id
> > +"-"+p.name[-1:]+p.filename[-4:])+" -resize 80x60 "+phpath
> > +"thm"+str("prop"+id+"-"+p.name[-1:]+p.filename[-4:])
> > R.write("\n\n"+com+"\n\n")
> > os.system(com)
> > if p.name[-1:]=="1":
> > com="convert "+phpath+str("tempprop"+id
> > +"-"+p.name[-1:]+p.filename[-4:])+" -resize 220x165\! "+phpath
> > +"bthm"+str("prop"+id+"-"+p.name[-1:]+p.filename[-4:])
> > R.write("\n\n"+com+"\n\n")
> > os.system(com)
> >
> > Sorry about the indentation, it got missed up while pasting in the
> > email.
> >
> > My guess is in 'p.file.read()
> >
> > How do I implemented for 2.7.11? or do I need to configure my Apache
> > conf file.
> >
> >
> >
> > ---------------------------------
> > Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously  
> low rates.
>
>
> How low will we go? Check out Yahoo! Messenger’s low PC-to-Phone  
> call rates.




More information about the Mod_python mailing list