Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda