Opened 2 years ago

Closed 2 years ago

#33948 closed Bug (invalid)

'Response' object has no attribute 'headers'

Reported by: Saran Owned by: nobody
Component: Core (Other) Version: 4.0
Severity: Release blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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/'>"}

Change History (1)

comment:1 by Carlton Gibson, 2 years ago

Resolution: invalid
Status: newclosed

HttpResponse.headers was added in Django https://docs.djangoproject.com/en/3.2/ref/request-response/#django.http.HttpResponse.headers
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.

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