0

Yesterday,when I try this function,it still working fine but today it suddenly shows this error,what is the problem?I could not post the complete coding,but I searched online,they said should be the if part problem,I have no idea how to fix it,someone please help,thank you!!!

def pdf(request, target_id):
   

    # to check is the report scan_id already exist
    for i in req.json().get("reports"):
        id_list = i['source']['id_list']

        # if the report scan_id is in the report which mean already exist
        if str(id_list)[2:-2] == scan_id:

           

            # using fileresponse to let the user download the file
            file = open('report.pdf', 'rb')
            response = FileResponse(file)
            response['Content-Type'] = 'application/octet-stream'
            response['Content-Disposition'] = 'attachment;filename="Web_vulnerability_scan_report.pdf"'
            return response
        # if the scan_id not found in the report
        else:
            
            req = requests.get(url=api_url, headers=HEADERS, verify=False)
            pdf_download = req.json().get("reports")[0].get("download")[1]

            print("report", pdf_download)
            pdf_url = TAR_URL+pdf_download

            r = requests.get(url=pdf_url, headers=HEADERS, verify=False)
            with open("report.pdf", "wb") as code:
                code.write(r.content)
                code.close
            file = open('report.pdf', 'rb')
            response = FileResponse(file)
            response['Content-Type'] = 'application/octet-stream'
            response['Content-Disposition'] = 'attachment;filename="Web_vulnerability_scan_report.pdf"'
            return response
Help
  • 11
  • 3

0 Answers0