I am a beginner and I need help

hello guys

I am working on a project to collect data from Octoprint for my internship,
but i can't test my code on 3Dprint because of containment,
the objective is sent the information retrieved from the API to a mongodb database

the information i need is:

  • printing id
  • the file name to print
  • file size
  • filament consumed in mm
  • how long the printing
def get_data_printing(self):
        
        address = self.address
        headers = {
            'X-Api-Key' : self.api_key,
            'Content-Type' : 'application/json'
        }
        try:
            settings.logger_global.LOGGER.info("Printing: Requête envoyé au octoprint")
            reponse_job = requests.get(address+"job", headers=headers, timeout=(4, 5))
        except requests.exceptions.Timeout as error:
            settings.logger_global.LOGGER.warning(error, exc_info=True)
            return ["Printing: Erreur la requête get prend trop de temps"]
        if reponse_job.status_code == 200:
            try:
                data_job = reponse_job.json()
            except RequestException as error:
                settings.logger_global.LOGGER.warning(error, exc_info=True)
                return ["Printing: Erreur l'adresse renvoie un status code 200 mais ne renvoie pas de json"]
            except JSONDecodeError as error:
                settings.logger_global.LOGGER.warning(error, exc_info=True)
                return ["Printing: Erreur l'adresse renvoie un status code 200 mais ne renvoie pas de json"]
            settings.logger_global.LOGGER.info("Printing: Requête reçus avec succès")
            return [
                    self.printing_id,
                    data_job['job']['file']['name'],
                    data_job['job']['file']['size'],
                    data_job['job']['file']['date'],
                    data_job['job']['filament']['length'],
                    data_job['progress']['printTime']]
        erreur = 'Printing: Erreur voici les codes de réponse {:d} {:d}'.format(reponse_job.status_code,
                                                                      reponse_printer.status_code)
        settings.logger_global.LOGGER.warning(erreur)
        return [erreur]

please, do you find that good? i need your ideas and your opinion

You actually CAN test without a real printer. There is a built-in Virtual Printer plugin and is fairly easy to enable. :slight_smile:

thank you sir :légèrement_smiling_face: