frappe.exceptions.ValidationError: Encryption key is invalid, Please check site_config.json

After I restore database, on bench migrate I have the following error
frappe.exceptions.ValidationError: Encryption key is invalid, Please check site_config.json
I did not have this error days ago when I tried bench migrate after restoring database.
It is a new server with ERP install from scratch.
This is the full Trace:

Executing frappe.patches.v8_7.update_email_queue_status in ec_erpnext (f623e199b1cf36a1)
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 217, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 31, in migrate
    frappe.modules.patch_handler.run_all()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 29, in run_all
    if not run_single(patchmodule = patch):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 63, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 83, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + ".execute")()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/patches/v8_7/update_email_queue_status.py", line 7, in execute
    default_email_account = get_default_outgoing_email_account()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/smtp.py", line 87, in get_default_outgoing_email_account
    email_account.password = email_account.get_password(raise_exception=False)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 664, in get_password
    return get_decrypted_password(self.doctype, self.name, fieldname, raise_exception=raise_exception)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/password.py", line 16, in get_decrypted_password
    return decrypt(auth[0][0])
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/password.py", line 106, in decrypt
    frappe.throw(_('Encryption key is invalid, Please check site_config.json'))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 319, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 309, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 282, in _raise_exception
    raise raise_exception(encode(msg))
frappe.exceptions.ValidationError: Encryption key is invalid, Please check site_config.json

@aldoblack you will need to copy the encryption keys from your old server. (they will be there in bench/sites/sitename/site_config.json)

8 Likes

Thanks. It worked.

I have the same problem. But I lost my site_config.json old file and I want update the last version I get same error. How can I update it?

Hi, that’s like losing the key to your safe

HI @rmehta,
Same error here. I did not change server. I believe it is because I have set up the email.
What could be the way forward? So is there a way to regenerate a new key?

@tundebabzy not very helpful comment, is it?

Thanks in advance.

Same here, i did not change server too.

I am also encountering the same error while saving a Leave Application

I’m facing the same issue while updating to v8.9.1 on the same server.

@Leonardo_Augusto @keshav Could you solve the issue?
Thanks

No, im not :confused:

Did not change server but only regular

bench update

brought up this …

I am also encountering the same error while saving the purchase order

Any update on this?? Encountered a similar issue while trying to update a site now it’s stuck on “Your system is being updated. Please refresh again after a few moments”

Kind regards,

p.s. I didn’t change servers (at least not recently)

BTW In my case specifically, the issue seems to be coming from the email account. I know that re-entering the password in the default outgoing Email Account will likely resolve this but the site is currently not accessible as stated in my post above

Please advise

Kind regards,

Any help here please? I tried removing the encryption key to see if the system would generate a new one but that didn’t seem to work

Thanks

@wale are you encountering with still encryption issue??

@wale try copying encryption key from source from where you have restore your database

1 Like

Hi @khushal_t

Thanks for your response. What are the options if I no longer have access to the source? Is there any way to regain access to the site so I can re-enter the email account password?

Thanks

Hi @wale,
There is no way to decrypt without the encryption key. That’s the whole purpose of it.
If it’s the same error above, you need to skip the patch. IMO two options,

Edit the patch file, pass the method
or
Set the default email outgoing accout as 0 in the DB

Hope you have access to the hosted instance
Thanks

2 Likes