Hi I’m trying to use Blocks for using secrets in my ETL. However, I keep on running into errors whe...
m
Hi I’m trying to use Blocks for using secrets in my ETL. However, I keep on running into errors when trying to load them:
Copy code
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [1], in <cell line: 6>()
      3 secret_block = Secret.load("etlharvestqaspassword")
      5 # Access the stored secret
----> 6 secret_block.get()

AttributeError: 'coroutine' object has no attribute 'get'
I defined the block within the Orion UI, because when I tried to define it via code in a simple script (as suggested here), I get the following kind of error:
Copy code
prefect.exceptions.PrefectHTTPStatusError: Client error '422 Unprocessable Entity' for url '<http://ephemeral-orion/api/block_documents/>'
Response: {'exception_message': 'Invalid request received.', 'exception_detail': [{'loc': ['body', 'name'], 'msg': 'name must only contain lowercase letters, numbers, and dashes', 'type': 'value_error'}, {'loc': ['body', '__root__'], 'msg': 'Names must be provided for block documents.', 'type': 'value_error'}], 'request_body': {'name': 'test2_password', 'data': {'value': 'test2'}, 'block_schema_id': '8019abd6-409a-4f91-9367-bc8343c31763', 'block_type_id': '29fb0ec8-f7e9-4527-984c-48f8675f2bc4', 'is_anonymous': False}}
For more information check: <https://httpstatuses.com/422>
I’m mostly using Prefect within a jupyter notebook and from within a virtualenv. Thanks in advance for anyone who could point me to what’s going on 🙂
m
Hey @Milan Valadou loading a secret would look more like this
Copy code
block = Secret.load("blockname")

block["nameofsecret"]
There's no get method on a secret block You can checkout more about it here https://docs.prefect.io/concepts/blocks/ As for the error you received it looks like the name you passed in contained an underscore(_) when it should only contain lowercase letters, numbers and dashes(-).
m
Hi @Mason Menges, thanks for your help, I’ll check it out! I guess I’m a bit confused because the example on the discourse seems to call
.get()
on a loaded Secret? I’m probably missing something, so thanks for clearing that up if it is the case 🙂
m
which discourse article are you referring to?
m
The Orion API also seems to suggest calling .get() on the Secret block, unless I’m mistaken 🙂
m
Nope that definitely looks correct, I was able to test it now to confirm, apologies there have been a lot of changes recently haha 😅. that said what version of prefect is installed in the jupyter notebook?
k
Also just want to confirm this is how you import Secret:
from prefect.blocks.system import Secret
m
@Mason Menges no problem! I understand, it’s been a lot of updates lately 😄 I was using version 2.0.2. In the meantime I found that using
.get()
works on a Block in jupyter notebooks, if you use
await
when creating the Block. Similarly, using
await
in a ‘normal’ flow (via a script) does result in an error.
1
m
I'm not terribly sure about what might be causing that, it might be related to how Jupyter notebooks handle async requests. many of the methods within prefects library are asynchronous in the background but it's setup in a way that you wouldn't normally need to await the get() method in a python script.
s
@Mason Menges Hey Mason, is there any update on what exactly is going on here. I'm having the same error as Milan where I'm using jupyter lab and
Copy code
from prefect.blocks.system import Secret

secret_block = Secret.load("slackbot-oauth")

secret_block.get()
results in
AttributeError: 'coroutine' object has no attribute 'get'
But
Copy code
from prefect.blocks.system import Secret

secret_block = await Secret.load("slackbot-oauth")

secret_block.get()
works. However, I would prefer my functions to not be asynchronous, but I have to make them asynchronous to use await. It would also be very nice to continue using jupyter lab, but for now I will use something else to dev in 2.0
819 Views