[Django] #33948: 'Response' object has no attribute 'headers'

573 views
Skip to first unread message

Django

unread,
Aug 23, 2022, 5:00:41 AM8/23/22
to django-...@googlegroups.com
#33948: 'Response' object has no attribute 'headers'
-------------------------------------------+------------------------
Reporter: Sarankrishna | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 4.0
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
I am getting error while calling REST API endpoint. It looks like this is
caused by the middleware
"django.middleware.clickjacking.XFrameOptionsMiddleware". we have
configured clickjacking middleware in django project like below. We were
not getting this error while using Django 2.0.4. But now we have upgraded
django version to 4.0.6. After the upgrade, we started getting this error
while calling REST API endpoint. Unable to understand why Response object
won't have header attribute. Refer below exception log

MIDDLEWARE = [
...
'django.middleware.clickjacking.XFrameOptionsMiddleware',
...
]

Exception Log
===========

{"asctime": "2022-08-21 10:20:45,228", "created": 1661077245.2283375,
"filename": "log.py", "funcName": "log_response", "levelname": "ERROR",
"levelno": 40, "lineno": 241, "module": "log", "msecs":
228.33752632141113, "message": "Internal Server Error:
/v1/zone/schemas/123-38b4-5591-8cfa-1234/", "name": "django.request",
"pathname": "/usr/local/lib/python3.10/site-packages/django/utils/log.py",
"process": 10, "processName": "MainProcess", "relativeCreated":
285498.6550807953, "thread": 140675831812672, "threadName": "Dummy-33",
"exc_info": "Traceback (most recent call last):\n File
\"/usr/local/lib/python3.10/site-
packages/django/core/handlers/exception.py\", line 55, in inner\n
response = get_response(request)\n File \"/usr/local/lib/python3.10/site-
packages/django/utils/deprecation.py\", line 136, in __call__\n
response = self.process_response(request, response)\n File
\"/usr/local/lib/python3.10/site-
packages/django/middleware/clickjacking.py\", line 27, in
process_response\n if response.get(\"X-Frame-Options\") is not None:\n
File \"/usr/local/lib/python3.10/site-packages/django/http/response.py\",
line 198, in get\n return self.headers.get(header,
alternate)\nAttributeError: 'Response' object has no attribute 'headers'",
"status_code": 500, "request": "<WSGIRequest: GET
'/v1/zone/schemas/123-38b4-5591-8cfa-1234/'>"}

--
Ticket URL: <https://code.djangoproject.com/ticket/33948>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 23, 2022, 5:50:52 AM8/23/22
to django-...@googlegroups.com
#33948: 'Response' object has no attribute 'headers'
---------------------------------+--------------------------------------
Reporter: Saran | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 4.0
Severity: Release blocker | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => invalid


Comment:

`HttpResponse.headers` was added in Django
https://docs.djangoproject.com/en/3.2/ref/request-
response/#django.http.HttpResponse.headers
[https://github.com/encode/django-rest-
framework/blob/master/rest_framework/response.py DRF's Response inherits
from Django's].

Maybe you have a cached response?

Either way, Trac is for issues reports in Django. Please see
TicketClosingReasons/UseSupportChannels for appropriate support channels.

--
Ticket URL: <https://code.djangoproject.com/ticket/33948#comment:1>

Reply all
Reply to author
Forward
0 new messages