Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
Django / Apache returns HTTP 500 Randomly

I have been dealing with a rather strange issue lately. My backend has httpd + mod wsgi + Django setup.

I have a class-based view as follows:

class ExtrasView(View):

def get(self, request):
    path = settings.BASE_DIR + "/data.json"
    with open(path, encoding='utf-8') as f:
        data = json.loads(f.read())
    return JsonResponse(data)

The get request to the above view works perfectly 9 out of 10 times. However, randomly this view would give a response with status 500. Based on the apache log, it seems that the response body length is correct i.e. the length of data in the file. This is verified by apache access logs.

Does anyone have an idea why this might be happening? I have checked the error logs and there's nothing in the errorlog. The error log does print tracebacks in case of exceptions or other syntax errors, just in this case it doesn't print anything so I'm clueless. Needless to say, the file being read is a static file that 100% exists.

The data in the file is huge, it's length is about 30-40k characters. Would this cause an issue? If yes, then why does it work 9 out of 10 times?

Any comments are welcome.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Why dont you just return the json file directly instead of loading it as json and returning it. Something like

def get(self, request)
    with open(path, encoding='utf-8') as f:
        return Response(f.read())
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda