Opened 5 years ago

Closed 5 years ago

#25424 closed Bug (fixed)

"AttributeError: '__proxy__' object has no attribute 'decode'" using reverse_lazy in test client

Reported by: Travis Jensen Owned by: Travis Jensen
Component: Testing framework Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This is basically the same as this bug, just starting from the test client. The relevant stack trace:

Traceback (most recent call last):
  File "$SRC/tests/", line 49,
    r = self.client.get(reverse_lazy('generator'))
  File "$HOME/venvs/webapp/lib/python3.4/site-packages/django/test/", line 500, in get
  File "$HOME/venvs/webapp/lib/python3.4/site-packages/django/test/", line 303, in get
    return self.generic('GET', path, secure=secure, **r)
  File "$HOME/venvs/webapp/lib/python3.4/site-packages/django/test/", line 357, in generic
    parsed = urlparse(path)
  File "$HOME/.pythonz/pythons/CPython-3.4.3/lib/python3.4/urllib/", line 292, in urlparse
    url, scheme, _coerce_result = _coerce_args(url, scheme)
  File "$HOME/.pythonz/pythons/CPython-3.4.3/lib/python3.4/urllib/", line 112, in _coerce_args
    return _decode_args(args) + (_encode_result,)
  File "$HOME/.pythonz/pythons/CPython-3.4.3/lib/python3.4/urllib/", line 96, in _decode_args
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: '__proxy__' object has no attribute 'decode'

Change History (5)

comment:1 Changed 5 years ago by Travis Jensen

Owner: changed from nobody to Travis Jensen
Status: newassigned

comment:2 Changed 5 years ago by Travis Jensen

I've created a reproducer and a fix for this, based on the fix for 18776. It is available at

This is my first foray into contributing to Django, so if there is anything I missed in terms of process and what-not, please let me know.

comment:3 Changed 5 years ago by Claude Paroz

Has patch: set
Triage Stage: UnreviewedAccepted

Could you please transform your branch into a pull request ?

comment:5 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: assignedclosed

In 1a09b3c:

Fixed #25424 -- Use force_str for test client URLs.

urlparse() fails with an AttributeError ("'proxy' object has no
attribute 'decode'") if reverse_lazy is used to look up the URL
(this is exactly the same problem that caused ticket #18776). The
solution is to use force_str() on the path before handing it to

Note: See TracTickets for help on using tickets.
Back to Top