''str' object has no attribute 'makefile'

Traceback (most recent call last): 
File "C:\Users\Rochak.virtualenvs\GFG\GFG\lib\site-packages\django\core\handlers\exception.py", line 47, in inner 
  response = get_response(request)
File "C:\Users\Rochak.virtualenvs\GFG\GFG\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
  response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Rochak.virtualenvs\GFG\GFG\Scripts\authentication\views.py", line 7, in home
  return HTTPResponse("Hello Rochak!")
File "C:\Program Files\Python310\lib\http\client.py", line 256, in init
  self.fp = sock.makefile("rb")

Exception Type: AttributeError at /authentication/hello/
Exception Value: 'str' object has no attribute 'makefile'


Solution 1:[1]

You're returning a http.client.HTTPResponse.

You need to return a django.http.HttpResponse.

Fix your import.

Solution 2:[2]

   #Remove http.client.HTTPResponse from import and follow:
   from django.shortcuts import render
   from django.http import HttpResponse

   # Create your views here.
   def home(request):
        return HttpResponse("Hello bro")

Solution 3:[3]

this is due to the capital of "TTP" in the return response - HTTPResponse but the correct one is the small letter of ttp like this:HttpResponse

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Rochak Bhattarai
Solution 3 Gebre Ajax