Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

500 Server Error when parsing some PDF

Aperta
#465 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
api, backend

Direzione di ricerca

Inizia riproducendo il POST a https://api.unstructured.io/general/v0/general con il file Mahmoud_Gamal_Resume.pdf allegato e la richiesta mostrata nell’issue, quindi confrontalo con un PDF che viene elaborato correttamente. L’issue è risolta quando questo PDF non produce più una risposta 500 e il suo risultato di parsing viene restituito correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
INFO:main:Detected file type: application/pdf INFO:main:Sending request to https://api.unstructured.io/general/v0/general INFO:main:Headers: {'Accept': 'application/json', 'unstructured-api-key': 'xxx'} INFO:main:File being sent: Mahmoud_Gamal_Resume.pdf INFO:main:Response status code: 500 INFO:main:Response headers: {'Date': 'Sun, 29 Sep 2024 21:51:15 GMT', 'Content-Type': 'application/json', 'Content-Length': '47', 'Connection': 'keep-alive', 'server': 'uvicorn'} ERROR:main:500 Internal Server Error: {"detail":"'6114cee903d6a72fa0370b97d042b71c'"} ERROR:main:Error details: { "detail": "'6114cee903d6a72fa0370b97d042b71c'" } HTTP error occurred: 500 Server Error: Internal Server Error for url: https://api.unstructured.io/general/v0/general

To Reproduce
A simple code to reproduce the error:

import requests
import json
import logging
import magic

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def is_pdf(file_path):
    mime = magic.Magic(mime=True)
    file_type = mime.from_file(file_path)
    logger.info(f"Detected file type: {file_type}")
    return file_type == "application/pdf"

def parse_pdf(api_key, file_path):
    if not is_pdf(file_path):
        return "Error: The provided file is not a PDF."

    url = "https://api.unstructured.io/general/v0/general"

    headers = {
        "Accept": "application/json",
        "unstructured-api-key": api_key
    }

    try:
        with open(file_path, "rb") as file:
            files = {"files": (file_path, file, "application/pdf")}
            
            logger.info(f"Sending request to {url}")
            logger.info(f"Headers: {headers}")
            logger.info(f"File being sent: {file_path}")
            
            response = requests.post(url, headers=headers, files=files)

        logger.info(f"Response status code: {response.status_code}")
        logger.info(f"Response headers: {response.headers}")

        response.raise_for_status()

        return response.json()
    except requests.exceptions.HTTPError as http_err:
        if response.status_code == 500:
            logger.error(f"500 Internal Server Error: {response.text}")
            try:
                error_details = response.json()
                logger.error(f"Error details: {json.dumps(error_details, indent=2)}")
            except json.JSONDecodeError:
                logger.error("Could not parse error response as JSON")
        return f"HTTP error occurred: {http_err}"
    except requests.exceptions.RequestException as err:
        return f"An error occurred: {err}"
    except Exception as e:
        return f"An unexpected error occurred: {e}"

def main():
    api_key = "YOUR_API_KEY_HERE"
    file_path = "Mahmoud_Gamal_Resume.pdf"

    result = parse_pdf(api_key, file_path)
    print(result)

if __name__ == "__main__":
    main()
  • Filetype: PDF
  • Any additional API parameters: No

Environment:

  • Ubuntu 22.04
  • SKD

Additional context
I attached one of the .pdf that produces such error, a side note when I used llamaparse it worked fine with this pdf
Mahmoud_Gamal_Resume.pdf

Lingua principale
Python
Stelle
953
Fork
192
Merge medio
1g 1h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Unstructured-IO/unstructured-api

Tutte le issue di Unstructured-IO/unstructured-api

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.