Opened 18 years ago
Closed 16 years ago
#4311 closed defect (fixed)
AttributeError: 'cStringIO.StringO' object has no attribute 'len'
Reported by: | anonymous | Owned by: | Matthew Good |
---|---|---|---|
Priority: | high | Milestone: | 0.10.4 |
Component: | general | Version: | 0.10.2 |
Severity: | normal | Keywords: | python25 |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Attaching files doesn't seem to work correctly anymore. This is Trac 0.10.2 and Python 2.5.
Python Traceback Traceback (most recent call last): File "/usr/lib64/python2.5/site-packages/trac/web/main.py", line 387, in dispatch_request dispatcher.dispatch(req) File "/usr/lib64/python2.5/site-packages/trac/web/main.py", line 238, in dispatch resp = chosen_handler.process_request(req) File "/usr/lib64/python2.5/site-packages/trac/attachment.py", line 361, in process_request self._do_save(req, attachment) File "/usr/lib64/python2.5/site-packages/trac/attachment.py", line 449, in _do_save size = upload.file.len AttributeError: 'cStringIO.StringO' object has no attribute 'len'
Attachments (0)
Change History (24)
comment:1 by , 18 years ago
comment:3 by , 18 years ago
Replying to anonymous:
Attaching files doesn't seem to work correctly anymore. This is Trac 0.10.2 and Python 2.5.
I don't think this is related to this very issue, but Trac 0.10 is known to have issues when run with Python 2.5, due to issues w/ ClearSilver.
comment:4 by , 18 years ago
Keywords: | needinfo added |
---|
Which web frontend are you using? FastCGI, mod_python, CGI, etc.? Which web server?
comment:5 by , 18 years ago
No fastcgi afaik
apache2-2.2.3-20 apache2-mod_python-3.2.10-27 python-2.5-19
what else do you need to know?
comment:6 by , 18 years ago
Keywords: | needinfo removed |
---|---|
Milestone: | → 0.10.3 |
Hmm, Python 2.5 changed the cgi
module to use cStringIO
for files if it's available, which unlike the StringIO
object doesn't support reading the length. I guess we need to find another way to check the size of the uploaded file.
comment:7 by , 18 years ago
My oh my.. I am not becoming a python fan. After wasting about 5h with wild guesses and restarting apache I found the following workaround seems to do it for my small test file. Don't know if it is worth anything.
if hasattr(upload.file, 'fileno'):
size = os.fstat(upload.file.fileno())[6]
else:
fstr = StringIO.StringIO(upload.file) size = fstr.len
comment:8 by , 18 years ago
I found the same error and observed that the error comes up, if the size of the uploaded file is smaller than 1kByte (approx.) Maybe this helps to find the reason.
comment:9 by , 18 years ago
Component: | ticket system → mod_python frontend |
---|---|
Keywords: | python25 added |
Owner: | changed from | to
comment:10 by , 18 years ago
Component: | mod_python frontend → general |
---|---|
Owner: | changed from | to
This is not specific to mod_python. The problem is due to the change in the Python cgi
module which is used by Trac for parsing POSTs on all frontends.
follow-up: 12 comment:11 by , 18 years ago
I think using the file-like interface ought to work since StringIO
and cStringIO
both provide it. This is constant time for both modules.
Tested on Python 2.4 and it works. Analysis of 2.5's source for cStringIO
shows it should work too.
-
trac/attachment.py
448 448 if hasattr(upload.file, 'fileno'): 449 449 size = os.fstat(upload.file.fileno())[6] 450 450 else: 451 size = upload.file.len 451 upload.file.seek(0, 2) 452 size = upload.file.tell() 453 upload.file.seek(0) 452 454 if size == 0: 453 455 raise TracError("Can't upload empty file")
comment:12 by , 18 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Replying to thatch:
I think using the file-like interface ought to work since
StringIO
andcStringIO
both provide it. This is constant time for both modules.
Aha, yes I figured there should be some other way to check the size, but I missed that seek()
supported seeking relative to the end of the file. That should do the trick.
comment:13 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
follow-up: 15 comment:14 by , 18 years ago
This bug is triggered by attempting to upload a vCard / vcf. These keywords should help others avoid submitting duplicate bugs.
comment:15 by , 18 years ago
Replying to demarco@maya.com:
This bug is triggered by attempting to upload a vCard / vcf. These keywords should help others avoid submitting duplicate bugs.
The problem is not dependent on the file type. It was an issue with an internal API that changed in Python 2.5.
comment:16 by , 17 years ago
Yup, I have this problem too:
DISTRIB_ID=Ubuntu DISTRIB_RELEASE=7.04 DISTRIB_CODENAME=feisty DISTRIB_DESCRIPTION="Ubuntu 7.04"
But, the patch fixed things for me. =)
comment:17 by , 17 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I am experiencing this bug in Trac 0.10.4 when trying to attach a file to a template.
Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 406, in dispatch_request dispatcher.dispatch(req) File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 237, in dispatch resp = chosen_handler.process_request(req) File "build/bdist.linux-i686/egg/WikiTemplates/attachment.py", line 363, in process_request self._do_save(req, attachment) File "build/bdist.linux-i686/egg/WikiTemplates/attachment.py", line 455, in _do_save size = upload.file.len AttributeError: 'cStringIO.StringO' object has no attribute 'len'
comment:18 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:19 by , 17 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Look again: this is when attaching a file to a template. I'm a Trac user, not an administrator - so I'm just reporting the bug. I know nothing of eggs. If the bug needs to go elsewhere, or is a separate issue, then please do what needs doing. I'm reporting it here because it is an identical bug to the previously fixed bug - just in a different place.
comment:20 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Ok, my bad, but that bug should be reported on http://wikitemplates.ufsoft.org/, where the WikiTemplates plugin is developed.
Closing again the ticket, as the problem is fixed in Trac itself.
comment:21 by , 17 years ago
You should also patch this line
size = f.len
with
f.seek(0, 2) size = f.tell() f.seek(0)
For newer cStringIO.
Cheers.
Alexo
comment:22 by , 17 years ago
comment:23 by , 16 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I have this error, if try to download small file (less then 1 kb).
My system Information: Trac: 0.11.1; Python: 2.5.2; TracDownloads: 0.2.
File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 423, in _dispatch_request dispatcher.dispatch(req) File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 197, in dispatch resp = chosen_handler.process_request(req) File "/usr/lib/python2.5/site-packages/trac/admin/web_ui.py", line 113, in process_request path_info) File "build/bdist.linux-x86_64/egg/tracdownloads/admin.py", line 43, in render_admin_panelFile "build/bdist.linux-x86_64/egg/tracdownloads/api.py", line 353, in process_downloadsFile "build/bdist.linux-x86_64/egg/tracdownloads/api.py", line 534, in _do_actionFile "build/bdist.linux-x86_64/egg/tracdownloads/api.py", line 813, in _get_file_from_req
comment:24 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
... line 534, in _do_actionFile "build/bdist.linux-x86_64/egg/tracdownloads/api.py", line 813, in _get_file_from_req
Please report this to TH:DownloadsPlugin.
The problem in Trac itself was fixed for 0.10.4 (see comment:13).
what platform are you on?