[FIXED] anvil.secrets.SecretError: No such secret

I am trying to test out the Secrets service, and I followed the examples precisely, but no matter how many encryption keys I add to my app, I keep getting this error in my server module: anvil.secrets.SecretError: No such secret 'my_key' <running on the server> called from /downlink/anvil/secrets.py, line 9

I am trying to use the encrypt_with_key and decrypt_with_key functions.

Any ideas?

Can you show us a screenshot of your Secrets Service config?

You don’t have a secret called “my_key”.

You do have an encryption key called “my_key” but they are not the same thing.

Right, but my server code is trying to use the encryption key: image

Can you please paste the actual line that causes the error? Because the error suggests you are calling get_secret not encrypt or decrypt.

It’s line 26:

image

image

I can confirm it does indeed do that…seeing if I can find out why…

are you importing other apps as dependencies?

see Secrets in dependencies

Nope, no dependencies:

Here’s a simple app that reproduces it :

https://anvil.works/build#clone:N6TJJM5YOBPQMIUP=NJTUPFPIT4HIP2DYILUTGTKH

Erm… @david.wylie, your app doesn’t have a key called fredkey! But if I change the code to encrypt with davekey, it works for me:

@anvil.server.callable
def dave():
  plain_text = "Some important data"
  encrypted_data = anvil.secrets.encrypt_with_key('davekey', plain_text)
  
  decrypted_data = anvil.secrets.decrypt_with_key('davekey', encrypted_data)
  print(decrypted_data)

That prints Some important data for me!

Yes it does ! Can you try re-downloading it just in case…?

I agree that davekey is now working - I swear it wasn’t as I only added fredkey because davekey didn’t work.

Both keys appear in the autocomplete, but fredkey is definitely not working for me,

EDIT
Hang on - if I reset the key value it seems to work now.

When I copied your app, I didn’t have fredkey either, it seemed to clone the app and rename the key back to new_key

Actually, I don’t think keys survive cloning.

For the sake of testing, can you click the “reset key” button to generate a new value, then see if that key works? Bear in mind you will lose anything already encrypted with that old key.

I just created a new project in the same way as before, and it works out of the box now.

Erm…

Ahaaa! This could be a saving issue. Try pressing Ctrl+S after editing your keys (to force a save of the whole app, not just the parts Anvil thinks have changed), and running it then. If that sorts it, I know where to look for the fix :slight_smile:

1 Like

Can confirm it is a saving issue! I created a brand new key, renamed it without saving, and got the same error. Then I went back and saved the page and it worked just fine.

2 Likes

Right! Moved to Bug Reports. We’ll get that fixed.

…and we’ve now deployed a fix.

1 Like