Ticket #5812 (closed defect: wontfix)
Opened 5 years ago
Last modified 2 years ago
[PATCH] Spamfilter monitor exception.
| Reported by: | grafikrobot@… | Owned by: | mgood |
|---|---|---|---|
| Priority: | normal | Milestone: | not applicable |
| Component: | plugin/spamfilter | Version: | 0.10.4 |
| Severity: | normal | Keywords: | unicode python23 |
| Cc: | |||
| Release Notes: | |||
| API Changes: | |||
Description
In the Boost trac we are getting a Python exception while trying to look at the spam log in the admin interface as:
Traceback (most recent call last):
File "/opt/trac/lib/python2.3/site-packages/trac/web/main.py", line 406, in dispatch_request
dispatcher.dispatch(req)
File "/opt/trac/lib/python2.3/site-packages/trac/web/main.py", line 237, in dispatch
resp = chosen_handler.process_request(req)
File "/opt/trac/boost/plugins/TracWebAdmin-0.1.2dev_r4240-py2.3.egg/webadmin/web_ui.py", line 109, in process_request
File "build/bdist.linux-i686/egg/tracspamfilter/admin.py", line 91, in process_admin_request
File "build/bdist.linux-i686/egg/tracspamfilter/admin.py", line 81, in render_admin_panel
File "build/bdist.linux-i686/egg/tracspamfilter/admin.py", line 178, in _render_monitoring_panel
File "build/bdist.linux-i686/egg/tracspamfilter/model.py", line 265, in select
File "build/bdist.linux-i686/egg/tracspamfilter/model.py", line 272, in _from_db
File "build/bdist.linux-i686/egg/tracspamfilter/model.py", line 82, in _decode_content
AttributeError: 'unicode' object has no attribute 'decode'
Attachments
Change History
comment:1 Changed 5 years ago by eblot
comment:2 Changed 5 years ago by grafikrobot@…
- Version set to 0.10.4
Per the link provided to the running trac instance, 0.10.4.
comment:3 Changed 5 years ago by thatch
I checked on Python 2.3.5 and the unicode type indeed doesn't have a decode method in that version.
comment:4 Changed 4 years ago by sid
So the suggested course of action is to upgrade to a later python version then?
comment:5 Changed 4 years ago by cboos
- Keywords unicode python23 added
- Milestone set to not applicable
comment:6 Changed 4 years ago by grafikrobot@…
Looking at the current code it seems there's an expectation that the DB, sqlite in the Boost case, will return "str" and not "unicode" strings. There are two "solutions" I can think of:
- Handle the AttributeError and assume it means the result is not base64.
- Ensure the decode('base64') is called only on an "str" object.
I'm attaching two patches for each one of those. But note that they are not tested in any form since I just don't know enough about the rest of the spamfilter context to know if they are entirely appropriate. And testing them directly on the Boost Trac install in not feasible (and I don't have an equivalent spare trac to test this on).
Changed 4 years ago by grafikrobot@…
- Attachment model.py.a.patch added
Ensure decode is called on str.
Changed 4 years ago by grafikrobot@…
- Attachment model.py.b.patch added
Handle the AttributeError? exception, and assume string is not base64 encoded.
comment:7 Changed 3 years ago by anonymous
I'm experiencing this problem. My output is slightly different:
File "/usr/lib/python2.3/site-packages/Trac-0.11.3-py2.3.egg/trac/web/main.py", line 435, in _dispatch_request
dispatcher.dispatch(req)
File "/usr/lib/python2.3/site-packages/Trac-0.11.3-py2.3.egg/trac/web/main.py", line 205, in dispatch
resp = chosen_handler.process_request(req)
File "/usr/lib/python2.3/site-packages/Trac-0.11.3-py2.3.egg/trac/admin/web_ui.py", line 113, in process_request
path_info)
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/admin.py", line 81, in render_admin_panel
data = self._render_monitoring_panel(req, cat, page)
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/admin.py", line 178, in _render_monitoring_panel
offset=offset))
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/model.py", line 265, in select
yield cls._from_db(env, row)
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/model.py", line 272, in _from_db
fields[6] = cls._decode_content(fields[6])
File "/usr/lib/python2.3/site-packages/TracSpamFilter-0.2.1dev_r7539-py2.3.egg/tracspamfilter/model.py", line 82, in _decode_content
return to_unicode(content.decode('base64'))
comment:8 Changed 3 years ago by anonymous
- Summary changed from Spamfilter monitor exception. to [PATCH] Spamfilter monitor exception.
comment:9 Changed 2 years ago by cboos
- Resolution set to wontfix
- Status changed from new to closed
#7118 was closed as duplicate.
The following error:
>>> u'sasd='.decode('base64')
AttributeError: 'unicode' object has no attribute 'decode'
is specific to Python 2.3.
In Python 2.4 and higher, it's perfectly legit:
>>> u'sasd='.decode('base64')
'\xb1\xab\x1d'
The content should be base64 encoded, otherwise will get one of the errors that we already check for.
I close it as wontfix, as I don't want to start adding more support for Python 2.3 at this point.
comment:10 Changed 2 years ago by cboos
(Michael, just remembering that you have commit rights on that plugin, and if your intent was to add support for Python 2.3, then please feel free to do so, just doing a str() cast would be enough).



Please specify which version of Trac you're using