from Crypto.PublicKey import RSA

from django.conf import settings
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = 'Randomly generate a new RSA key for the OpenID server'

    def handle(self, *args, **options):
        try:
            key = RSA.generate(1024)
            file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
            with open(file_path, 'w') as f:
                f.write(key.exportKey('PEM'))
            self.stdout.write('RSA key successfully created at: ' + file_path)
        except Exception as e:
            self.stdout.write('Something goes wrong: ' + e.message)

from Crypto.PublicKey import RSA

from django.conf import settings
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = 'Randomly generate a new RSA key for the OpenID server'

    def handle(self, *args, **options):
        try:
            key = RSA.generate(1024)
            file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
            with open(file_path, 'w') as f:
                f.write(key.exportKey('PEM'))
            self.stdout.write('RSA key successfully created at: ' + file_path)
        except Exception as e:
            self.stdout.write('Something goes wrong: {0}'.format(e))

Fix use of deprecated Exception.message in Python 3
Fix use of deprecated Exception.message in Python 3

  from Crypto.PublicKey import RSA
  
  from django.conf import settings
  from django.core.management.base import BaseCommand
  
  
  class Command(BaseCommand):
      help = 'Randomly generate a new RSA key for the OpenID server'
  
      def handle(self, *args, **options):
          try:
              key = RSA.generate(1024)
              file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
              with open(file_path, 'w') as f:
                  f.write(key.exportKey('PEM'))
              self.stdout.write('RSA key successfully created at: ' + file_path)
          except Exception as e:
-             self.stdout.write('Something goes wrong: ' + e.message)
+             self.stdout.write('Something goes wrong: {0}'.format(e))
  
Fix use of deprecated Exception.message in Python 3
## Code Before:
from Crypto.PublicKey import RSA

from django.conf import settings
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = 'Randomly generate a new RSA key for the OpenID server'

    def handle(self, *args, **options):
        try:
            key = RSA.generate(1024)
            file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
            with open(file_path, 'w') as f:
                f.write(key.exportKey('PEM'))
            self.stdout.write('RSA key successfully created at: ' + file_path)
        except Exception as e:
            self.stdout.write('Something goes wrong: ' + e.message)

## Instruction:
Fix use of deprecated Exception.message in Python 3
## Code After:
from Crypto.PublicKey import RSA

from django.conf import settings
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = 'Randomly generate a new RSA key for the OpenID server'

    def handle(self, *args, **options):
        try:
            key = RSA.generate(1024)
            file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
            with open(file_path, 'w') as f:
                f.write(key.exportKey('PEM'))
            self.stdout.write('RSA key successfully created at: ' + file_path)
        except Exception as e:
            self.stdout.write('Something goes wrong: {0}'.format(e))
