This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib2 maximum recursion depth exceeded
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: berker.peksag, ezio.melotti, jhylton, nako521, orsenthil, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2009-07-17 08:26 by nako521, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue6500.diff berker.peksag, 2015-08-03 00:41
issue6500_2.patch serhiy.storchaka, 2016-01-06 01:56 review
Messages (13)
msg90612 - (view) Author: simon (nako521) Date: 2009-07-17 08:26
def __getattr__(self, attr):
        # XXX this is a fallback mechanism to guard against these
        # methods getting called in a non-standard order.  this may be
        # too complicated and/or unnecessary.
        # XXX should the __r_XXX attributes be public?
        if attr[:12] == '_Request__r_':
            name = attr[12:]
            if hasattr(Request, 'get_' + name):
                getattr(self, 'get_' + name)()
                return getattr(self, attr)
        raise AttributeError, attr

this may cause "maximum recursion depth exceeded"

>>> import urllib2
>>> req = urllib2.Request('http://www.nbc.com')
>>> req._Request__r_method
RuntimeError: maximum recursion depth exceeded

"return getattr(self, attr)"? should it be removed?
msg90615 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-07-17 09:19
That __getattr__ was removed in r70815 and in Python 3.1 it's OK.
The change wasn't backported to the trunk though.

Assigning to Jeremy to see what he thinks about it.
msg100258 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2010-03-01 16:36
Ok.  I'll take a look, too.

Jeremy

On Sat, Feb 27, 2010 at 4:30 AM, Ezio Melotti <report@bugs.python.org> wrote:
>
> Changes by Ezio Melotti <ezio.melotti@gmail.com>:
>
>
> ----------
> nosy: +orsenthil
> status: pending -> open
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue6500>
> _______________________________________
>
msg247916 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-08-03 00:41
Here is a patch for 2.7. I don't think backporting 9eceb618274a to 2.7  is worth the effort for this, so I just fixed the __getattr__ method and added a test.
msg257373 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-01-02 22:23
Thank you Ezio, I'll commit this tomorrow.
msg257566 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-01-06 00:05
New changeset fbea8ff8db5e by Berker Peksag in branch '2.7':
Issue #6500: Fix "maximum recursion depth exceeded" error caused by Request.__getattr__()
https://hg.python.org/cpython/rev/fbea8ff8db5e
msg257569 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-06 00:19
Hi @Berker,

This patch breaks the unit tests. Could you confirm (or reject) this?
Thanks
msg257572 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-01-06 01:08
New changeset e2faa18802bb by Berker Peksag in branch '2.7':
Issue #6500: Reverting fbea8ff8db5e since it broke tests
https://hg.python.org/cpython/rev/e2faa18802bb
msg257573 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-01-06 01:10
Thanks, Senthil. I've just reverted fbea8ff8db5e. Sorry for the noise!
msg257575 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-06 01:56
__getattr__() was purposed to handle two lazily created private attributes: __r_type and __r_host. They are set in corresponding get_-methods.

Here is a patch that makes __getattr__() to handle only these attributes.
msg258495 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-18 03:28
@Serhiy, the patch looks good to me. This change is an excellent idea. Please commit it.
msg258504 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-01-18 08:40
New changeset d34fdd1736f2 by Serhiy Storchaka in branch '2.7':
Issue #6500: Fixed infinite recursion in urllib2.Request.__getattr__().
https://hg.python.org/cpython/rev/d34fdd1736f2
msg258506 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-18 08:59
Thank you for the review Senthil.
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50749
2016-01-18 08:59:33serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg258506

stage: commit review -> resolved
2016-01-18 08:40:50python-devsetmessages: + msg258504
2016-01-18 03:28:23orsenthilsetassignee: berker.peksag -> serhiy.storchaka
messages: + msg258495
stage: patch review -> commit review
2016-01-06 01:56:14serhiy.storchakasetfiles: + issue6500_2.patch

nosy: + serhiy.storchaka
messages: + msg257575

stage: needs patch -> patch review
2016-01-06 01:10:02berker.peksagsetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg257573

stage: resolved -> needs patch
2016-01-06 01:08:21python-devsetmessages: + msg257572
2016-01-06 00:19:43orsenthilsetmessages: + msg257569
2016-01-06 00:05:36berker.peksagsetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2016-01-06 00:05:01python-devsetnosy: + python-dev
messages: + msg257566
2016-01-02 22:23:14berker.peksagsetassignee: jhylton -> berker.peksag
messages: + msg257373
2016-01-01 23:20:48ezio.melottisetstage: patch review -> commit review
2015-08-03 00:41:45berker.peksagsetfiles: + issue6500.diff

nosy: + berker.peksag
messages: + msg247916

keywords: + patch
stage: needs patch -> patch review
2012-11-18 21:08:22ezio.melottisetstage: needs patch
2010-03-01 16:36:04jhyltonsetmessages: + msg100258
2010-02-27 09:30:10ezio.melottisetstatus: pending -> open
nosy: + orsenthil
2009-07-17 09:19:21ezio.melottisetstatus: open -> pending
priority: normal

assignee: jhylton
versions: + Python 2.7, - Python 2.6, Python 2.5, Python 2.4
nosy: + jhylton, ezio.melotti

messages: + msg90615
2009-07-17 08:26:12nako521create