Edgewall Software
Modify

Opened 20 years ago

Closed 19 years ago

Last modified 18 years ago

#554 closed defect (fixed)

Attachments doesn't work with mod_python and windows

Reported by: ian.leader@… Owned by: Christopher Lenz
Priority: normal Milestone: 0.10
Component: web frontend/mod_python Version: 0.9.3
Severity: major Keywords: mod_python attachments windows wsgi
Cc: rhind@…, nunterberg@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

The attachments page does not work for me under the following configuration:

  • W2K server, Apache 2.0.48, Python 2.3.4, mod_python 3.1.3

When you select a file and fill out the description field and press 'Add' the page resets all fields to blank, but the file is not attached.

If I switch to cgi, everything works fine.

Attachments (3)

util_py.patch (1.8 KB ) - added by paul.kendall@… 20 years ago.
mod_python patch to fix this issue
util.py (12.1 KB ) - added by anonymous 19 years ago.
importlog.txt (20.8 KB ) - added by mwilliams 18 years ago.
dir

Download all attachments as: .zip

Change History (51)

comment:1 by daniel, 20 years ago

Milestone: 0.8
Priority: normalhighest
Severity: normalcritical

comment:2 by daniel, 20 years ago

Component: generalmod_python frontend

comment:3 by Jonas Borgström, 20 years ago

Is this still the case?

I just tested attaching files with firefox and safari on 0.7-stable (rev 817) running os OSX and it seems to work.

You maybe need to set the TracUriRoot variable, see ModPython.

comment:4 by Jonas Borgström, 20 years ago

Status: newassigned

comment:5 by Ian Leader <ian_dot_leader_at_line_dot_co_dot_uk>, 20 years ago

I'm starting to wonder if this is a Windows-server-only-thing or a windows-server-and-IE-don't-behave-together thing. I'll check with some different browsers and see where I get to.

comment:6 by Ian Leader <ian_dot_leader_at_line_dot_co_dot_uk>, 20 years ago

OK - tried two different configurations, 0.7-stable, and trunk Head (828) with IE 6 & Firefox 0.92, and I'm getting the same problem, as described in the original posting of the ticket. TracURIRoot is set. Full configuration below:

Config 1 ========

Server: Windows XP SP1, Apache 2.0.48 (Win32) / mod_python 3.1.1 / Python 2.3.4 Trac: 0.7-stable branch HEAD revision (805) Client: Windows XP SP1 (same box as server), Web Browser: IE 6.0.2800 & Firefox 0.9.2

Apache Config:

# TRAC Config

Alias /trac "c:/Python23/share/trac/htdocs"

<Directory "c:/Python23/share/trac/htdocs">

Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all

</Directory>

<Location "/cgi-bin/trac.cgi">

SetEnv TRAC_ENV "c:\temp\trac\test-0.7-stable"

</Location>

<LocationMatch /tracproj>

SetHandler mod_python PythonHandler trac.ModPythonHandler PythonOption TracUriRoot /tracproj PythonOption TracEnvParentDir "c:\temp\trac"

</LocationMatch>

Config 2 ========

Server: Windows XP SP1, Apache 2.0.48 (Win32) / mod_python 3.1.1 / Python 2.3.4 Trac: trunk HEAD revision (828) Client: Windows XP SP1 (same box as server), Web Browser: IE 6.0.2800 & Firefox 0.9.2

Apache Config

# TRAC Config

Alias /trac "c:/Python23/share/trac/htdocs"

<Directory "c:/Python23/share/trac/htdocs">

Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all

</Directory>

<Location "/cgi-bin/trac.cgi">

SetEnv TRAC_ENV "c:\temp\trac\test-trunk"

</Location>

<LocationMatch /tracproj>

SetHandler mod_python PythonHandler trac.ModPythonHandler PythonOption TracUriRoot /tracproj PythonOption TracEnvParentDir "c:\temp\trac"

</LocationMatch>

comment:7 by Ian Leader <ian_dot_leader_at_line_dot_co_dot_uk>, 20 years ago

Config in last comment was a right formatting mess. Try again:

Config 1
========

Server: Windows XP SP1, Apache 2.0.48 (Win32) / mod_python 3.1.1 / Python 2.3.4
Trac: 0.7-stable branch HEAD revision (805)
Client: Windows XP SP1 (same box as server), Web Browser: IE 6.0.2800 & Firefox 0.9.2
URL accessed for mod_python test: http://localhost:9877/tracproj/test-0.7-stable

Apache Config:


# TRAC Config

Alias /trac "c:/Python23/share/trac/htdocs"

<Directory "c:/Python23/share/trac/htdocs">
  Options Indexes MultiViews
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

<Location "/cgi-bin/trac.cgi">

  SetEnv TRAC_ENV "c:\temp\trac\test-0.7-stable"
  
</Location>

<LocationMatch /tracproj>
  SetHandler mod_python
  PythonHandler trac.ModPythonHandler
  PythonOption TracUriRoot /tracproj
  PythonOption TracEnvParentDir "c:\temp\trac"
</LocationMatch>


Config 2
========

Server: Windows XP SP1, Apache 2.0.48 (Win32) / mod_python 3.1.1 / Python 2.3.4
Trac: trunk HEAD revision (828)
Client: Windows XP SP1 (same box as server), Web Browser: IE 6.0.2800 & Firefox 0.9.2
URL accessed for mod_python test: http://localhost:9877/tracproj/test-trunk

Apache Config


# TRAC Config

Alias /trac "c:/Python23/share/trac/htdocs"

<Directory "c:/Python23/share/trac/htdocs">
  Options Indexes MultiViews
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

<Location "/cgi-bin/trac.cgi">

  SetEnv TRAC_ENV "c:\temp\trac\test-trunk"
  
</Location>

<LocationMatch /tracproj>
  SetHandler mod_python
  PythonHandler trac.ModPythonHandler
  PythonOption TracUriRoot /tracproj
  PythonOption TracEnvParentDir "c:\temp\trac"
</LocationMatch>

comment:8 by Jonas Borgström, 20 years ago

Ok, seems to be a win32-only problem. I'll try to dig up a win32 box to test this on…

comment:9 by Jonas Borgström, 20 years ago

Keywords: win32 added

comment:10 by Jonas Borgström, 20 years ago

Status: assignednew

comment:11 by Jonas Borgström, 20 years ago

Summary: Attachments don't attach when using mod_python as of 0.7-stable revision 744Attachments doesn't work with mod_python and windows

I need help by some windows hacker to debug and fix this one.

comment:12 by paul.kendall@…, 20 years ago

I've just spent a few hours going through a debug session and found that this bug is caused by a bug in mod_python's util.py file!

They have patched it in their CVS. It should be broken on all platforms, not just Windows.

I'll also include the patch here.

by paul.kendall@…, 20 years ago

Attachment: util_py.patch added

mod_python patch to fix this issue

comment:13 by paul.kendall@…, 20 years ago

Actually after further investigation it's actually a feature of Python 2.2 & 2.3! The mod_python patch is a workaround. I don't think it's going to be possible to make a patch to Trac to workaround the problem either so we may just have to document this issue for Python.

Python 2.1 doesn't have this problem because yo have to use the earlier mod_python.

comment:14 by ___ian.leader@…, 20 years ago

I've just tested the patch on our test server and attachments finally work!

Jonas, Paul - thank you very much for putting the time and effort in to resolve this problem.

I've updated the ModPython wiki page with a note on this.

comment:15 by Jonas Borgström, 20 years ago

Milestone: 0.80.9

Good work Ian. I'm moving this ticket to 0.9 now because there's no point in blocking a 0.8 release just for this. But I think this ticket should stay open until a upstream version of modpython containing this patch has been released…

comment:16 by john@…, 20 years ago

Resolution: fixed
Status: newclosed

This will hopefully not succeed?!

comment:17 by anonymous, 20 years ago

Resolution: fixed
Status: closedreopened

comment:18 by cam@…, 20 years ago

Version: 0.7.10.8

Even with the util.py patch attachments didn't work for me on Apache/2.0.52 (Win32) mod_python/3.1.3 Python/2.3.4. and Trac-0.8-stable.

comment:19 by rhind@…, 20 years ago

Cc: rhind@… added

They don't work for me either, win32, apache-2.0.52, mod-python 3.1.3, python-2.3.4

comment:20 by rhind@…, 20 years ago

Should add that have the problem in both trac-0.8 and trac-0.8.1

comment:21 by rhind@…, 20 years ago

Ok, after thoroughly reading this thread, I realise I have to patch util.py that comes with mod_python. I have applied the patch, but how do I re-generate util.pyc and util.pyo. when I try with python, I get an error saying no module named _apache for the 'import _apache' line. Apparently this module is defined in mod_python loaded by apache.

So in that case, how do we re-compile the patched util.py?

comment:22 by rhind@…, 20 years ago

Ok, I know nothing about python. I had a permissions problem. I generated the patched file through cygwin and it changed the permissions on util.py (cygwin never gives SYSTEM any permissions) which caused apache not to be able to read the file.

Changed the permissions to give SYSTEM full control fixed it and I can now attach files.

Cheers

Russell

comment:23 by matthias.hryniszak@…, 19 years ago

The problem is still there on 0.8.4 using mod_python with Apache 2.0.54. I already assignen all permission for to the SYSTEM account and it still doesn't work.

Help!

Matthias.

comment:24 by Matthew Good, 19 years ago

This is a mod_python problem, not Trac, so upgrading your Trac version is not going to fix it. You need to apply the patch attached to this ticket. The problem with SYSTEM permissions was simply that in the process of applying the patch he accidentally changed the permissions on the file as well.

comment:25 by Shun-ichi Goto <gotoh@…>, 19 years ago

Worksforme. Now I'm using svn-HEAD of Trac with apache-2.0.54 and patch for util.py. The patch works well since 2004/12 (0.8.1?) until today (0.9pre). What is the problem? What does apache log says on fail?

comment:26 by jim@…, 19 years ago

Trac Environment:

  • Windows XP Pro
  • Apache 2.0.53
  • mod_python 3.1.3
  • Subversion 1.1.4
  • pysqlite 1.1.6

I've been running 0.8.4 smoothly for a couple of months now on a test basis, including successfully applying and using the patch to util.py called for here. I've just upgraded to 0.9.1b and have run into problem with new and existing attachments.

For existing attachments, behavior depends on the type of file attached. .txt or .gif files are displayed correctly on the attachement page. However, on the attachment page there is no link to the attached file itself and, therefore, no way to download that file. For a word document or powerpoint file, for example, the attachment page has nothing displayed and no link to a file I might download.

For new attachments, browsing to a file to attach appears to work, but the end result is the same as described above for existing attachments.

comment:27 by sid, 19 years ago

Worked for me today.

Running Windows Small Business Server 2003 with Trac 0.9b1, mod_python 3.1.3

comment:28 by leasun, 19 years ago

Version: 0.80.9b1

I found new problem about attachment. My server: Windows XP SP1 Apache 2.0.54 Python 2.3.5 svn 1.2.1 mod_python 3.1.3

trac 0.9b1

I want to add a new attachment, and after I fill the filename and clicked the Add button, I get this error:

Oops… Trac detected an internal error: 'StringField' object has no attribute 'filename'If you think this really should work and you can reproduce it. Then you should consider to report this problem to the Trac team.

Go to http://trac.edgewall.com/ and create a new ticket where you describe the problem, how to reproduce it. Don't forget to include the python traceback found below.

TracGuide — The Trac User and Administration Guide

Python traceback Traceback (most recent call last):

File "D:\develop\Python\2.3\Lib\site-packages\trac\web\modpython_frontend.py", line 205, in handler

dispatch_request(mpr.path_info, mpr, env)

File "D:\develop\Python\2.3\Lib\site-packages\trac\web\main.py", line 139, in dispatch_request

dispatcher.dispatch(req)

File "D:\develop\Python\2.3\Lib\site-packages\trac\web\main.py", line 107, in dispatch

resp = chosen_handler.process_request(req)

File "D:\develop\Python\2.3\lib\site-packages\trac\attachment.py", line 265, in process_request

self._do_save(req, attachment)

File "D:\develop\Python\2.3\lib\site-packages\trac\attachment.py", line 296, in _do_save

if not upload.filename:

AttributeError: 'StringField' object has no attribute 'filename'

I found that the upload just get the file content not the attachment form data. Is it a bug of mod_python? or trac?

comment:29 by leasun, 19 years ago

And in cgi, there no that problem.

comment:30 by Emmanuel Blot, 19 years ago

I can confirm the issue with WinXP SP2 Apache 2.0.54 ModPython 3.1.3, and Trac [2252], with and without the initial modpython patch.

comment:31 by Kent, 19 years ago

I was having an issue where I wasn't able to upload files even after applying the patch to mod_python.

The following error message was being logged by Apache:

Exception exceptions.RuntimeError: 'instance.__dict__ not accessible in restricted mode' in  ignored
Exception exceptions.RuntimeError: 'instance.__dict__ not accessible in restricted mode' in  ignored
Exception exceptions.RuntimeError: 'instance.__dict__ not accessible in restricted mode' in  ignored
[Fri Sep 23 11:27:02 2005] [notice] Child 1488: Child process is exiting

Upon further investigation I found it was just files that were larger than the max limit set in trac.ini.

The weird part is the message telling me this didn't display on my regular machine, but only in the VPC where I was running the test install of Trac.

I altered the limit in the trac.ini file and it now works for me.

Hope this helps someone.

Apache/2.0.54 (Win32) SVN/1.2.3 mod_python/3.1.3 Python/2.3.5 Windows 2003 (in VPC) Trac/9.1b

comment:32 by Norbert Unterberg <nunterberg@…>, 19 years ago

Cc: nunterberg@… added

comment:33 by Ian Leader <__ian.leader__@…>, 19 years ago

New ticket raised against jim@… comment as #2144 as I believ this is a different issue.

comment:34 by Christian Boos, 19 years ago

Owner: changed from Jonas Borgström to Christian Boos
Status: reopenednew

I finally got Apache installed on my windows machine (using XAMPP for windows) and I could reproduce the issue:

Traceback (most recent call last):
  File "D:\Workspace\install\lib\python\trac\devel\Lib\site-packages\trac\web\modpython_frontend.py", line 206, in handler
    dispatch_request(mpr.path_info, mpr, env)
  File "D:\Workspace\install\lib\python\trac\devel\Lib\site-packages\trac\web\main.py", line 139, in dispatch_request
    dispatcher.dispatch(req)
  File "D:\Workspace\install\lib\python\trac\devel\Lib\site-packages\trac\web\main.py", line 107, in dispatch
    resp = chosen_handler.process_request(req)
  File "D:\Workspace\install\lib\python\trac\devel\Lib\site-packages\trac\attachment.py", line 265, in process_request
    self._do_save(req, attachment)
  File "D:\Workspace\install\lib\python\trac\devel\Lib\site-packages\trac\attachment.py", line 296, in _do_save
    if not upload.filename:

The above was without the attachment:util_py.patch

Now, with the patch applied:

$ cd $PYTHONHOME/Lib/site-packages/mod_python
$ cp util.py util.py-orig
$ rm util.pyc 
$ rm util.pyo
$ patch < util_py.patch
(Stripping trailing CRs from patch.)
patching file util.py

… the problem is gone.

I'll try to have a look if we can do something about that from within Trac (i.e. without the patch). At least some kind of warning could be produced.

comment:35 by Christian Boos, 19 years ago

Status: newassigned

I propose to issue the following warning:

  • attachment.py

     
    293293            req.redirect(attachment.parent_href)
    294294
    295295        upload = req.args['attachment']
     296        if not hasattr(upload, 'file'):
     297            raise TracError('Attachment won\'t work with this version of '
     298                            'ModPython. See <a href="%s">%s</a>.' \
     299                            %  ('http://projects.edgewall.com/trac/wiki/'
     300                                'TracModPython#Win32Issues',
     301                                'TracModPython / Win32 issues'))
    296302        if not upload.filename:
    297303            raise TracError, 'No file uploaded'
    298304        if hasattr(upload.file, 'fileno'):

Also, the targeted documentation (TracModPython#Win32Issues) has been expanded a bit.

comment:36 by anonymous, 19 years ago

Do you know if the issue is fixed for 3.2.2 which is now in beta? (I'm not planning on upgrading to the beta, but just wondered for when 3.2.2 final is released)?

Thanks

Russell

comment:37 by Christian Boos, 19 years ago

Not tested, but yes, the fix is in the trunk as well as in the 3-2-3b tag, which means that this specific problem will be solved in the 3.2.x line.

Of course, there might be other problems with Trac and mod_python 3.2.x, so an upgrade is not the recommended solution at this point.

comment:38 by Christian Boos, 19 years ago

Milestone: 0.9
Priority: highesthigh
Severity: criticalmajor

Ok, we decided to postpone closing this ticket at the time mod_python 3.2.x will be release and becomes the recommended version to use for Trac.

In the meantime, the issue is now well documented.

by anonymous, 19 years ago

Attachment: util.py added

comment:39 by kevin, 19 years ago

just as an update, I have tried using trac-0.9.2 with mod-python-3.2.5b on win2k server and it doesn't seem to work.

I examined the util.py file included on mod-python-3.2.5b and it appears to already include the added lines from the patchfile.

When I try to upload a file I get an: Error No file uploaded.

page.

comment:40 by Kevin, 19 years ago

nevermind, it appears to be working with binary files.

tried with an .exe file and it uploaded fine.

however an empty .txt file produced the error.

seems to be working.

comment:41 by anonymous, 19 years ago

Priority: highnormal
Version: 0.9b10.9.3

I am using Apache 2.0.55, Python 2.3.5, Trac 0.9.3 and get the message 'StringField' object has no attribute 'filename'

here is the traceback:

Traceback (most recent call last):
  File "C:\Python23\Lib\site-packages\trac\web\modpython_frontend.py", line 206, in handler
    dispatch_request(mpr.path_info, mpr, env)
  File "C:\Python23\Lib\site-packages\trac\web\main.py", line 139, in dispatch_request
    dispatcher.dispatch(req)
  File "C:\Python23\Lib\site-packages\trac\web\main.py", line 107, in dispatch
    resp = chosen_handler.process_request(req)
  File "C:\Python23\Lib\site-packages\trac\attachment.py", line 267, in process_request
    self._do_save(req, attachment)
  File "C:\Python23\Lib\site-packages\trac\attachment.py", line 298, in _do_save
    if not upload.filename:
AttributeError: 'StringField' object has no attribute 'filename'

i tried to copy the util.py inte the mod_python directory, but nothing changed.

i am pretty new to python, so what else can i check to be sure, i have done everything right?

comment:42 by Russell Hind <rhind@…>, 19 years ago

I've just re-installed our server because of a drive crash, and am now running with apache 2.0.55 and got the same error. I replaced util.py.

Did you restart the web server? You might also need to delete the util.pyc and util.pyo files too (not too sure about that). After doing this, I can upload attachments.

Cheers

Russell

comment:43 by Christopher Lenz, 19 years ago

Keywords: wsgi added
Milestone: 0.10
Owner: changed from Christian Boos to Christopher Lenz
Status: assignednew

This whole problem is going to go away once the WSGI branch is migrated. If you have a chance, please try the branch out.

comment:44 by Russell Hind <rhind@…>, 19 years ago

Is there a guide posted for how to use trac with WSGI? (Similar to TracModPython?) I would test it, but I think I'll have to wait until 0.10 comes out because I've currently only ever installed from the windows installers, don't actually known python myself so performing a manual installation from a branch is probably out of my scope for now.

Thanks

Russell

comment:45 by anonymous, 19 years ago

Replacing util.py, deleting util.pyc and util.pyo and restarting apache works fine.

Now i can upload attachments! Thanks for your fast replies!

comment:46 by jornh, 19 years ago

http://www.modpython.org/ says: Feb-09-2006 3.2.7 is out and available on the download page.

That release contains the patch attached above. I have updated TracModPython#Win32Issues accordingly.

comment:47 by Christopher Lenz, 19 years ago

Resolution: fixed
Status: newclosed

The WSGI branch was merged into trunk in [2957], so this issue should now be fixed.

by mwilliams, 18 years ago

Attachment: importlog.txt added

dir

comment:48 by sid, 18 years ago

Keywords: windows added; win32 removed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christopher Lenz.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christopher Lenz to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.