Why am I encountering a NameError when importing the 'google-auth' package in a Pipedream Python code block?

This topic was automatically generated from Slack. You can find the original thread here.

Hi,

I’m currently experiencing an issue while trying to use the google-auth package in a Pipedream Python code block. I’m attempting to import the package as described on the pipedream docs to no avail.

Below is an example of how I am importing it:

# pipedream add-package google-auth
from google.oauth2 import service_account
# pipedream add-package google-cloud-compute
from google.cloud import compute_v1

And here is the error that I get in return:

NameError
name 'service_account' is not defined

This exact code works perfectly fine locally so I’m quite confused. Any help would be much appreciated.

Is there anyway you would be able to look into this for me please.

Hi , thank you for reaching out. I missed this.

Pipedream runs your code in an AWS Lambda function, so it’s not similar to your local machine.

My recommendation is to use Pipedream prebuilt actions - Google Cloud app in this case, it would ensure that you use the well tested code.

If there’re some actions missing for your usecase, feel free to submit a ticket

Hi , our team has previously attempted to use prebuilt actions and experienced issues so we tend to do logic like this through custom code blocks to ensure we have full control over them and can fix bugs swiftly without being reliant upon 3rd party tooling.

Just to clarify is this issue not possible to fix? In the documentation for magic comments GCP’s ‘Big Query’ is used as an example and authentication would be required for that as well through most likely something like google-auth which we are using so I’m slightly confused around this.

AFAIK, you can only use the magic comments on the package defined on that document.

Not sure what is the process to add new package (cc )

Another recommendation is that you can also switch to Node.js, since that’s the language that Pipedream actions are implemented on.

I’ve had a quick look at the Google Cloud app on Pipedream and it doesn’t support any compute engine endpoints which we would need to use said app.

Node.js also isn’t really an option due to the limited number of Node.js developers on our end.

If you could check internally if there is anyway to fix the packaging issue we are running into it would be much appreciated.

If you could check internally if there is anyway to fix the packaging issue we are running into it would be much appreciated.
Yeah for this I’ve looped in for him to aware.

I’m checking with the team and will post an update when I have one. I’m not too familiar with python code steps myself.

Hey looks like the issue is that the comments all have to be at the top, for example:

# pipedream add-package google-auth
# pipedream add-package google-cloud-compute
from google.oauth2 import service_account
from google.cloud import compute_v1

Try this and let me know if you still run into any issues

Hi ,

Thank you for looking into this for me, this does seem to fix it.

Just a little heads up, the wording on the Magic Comments Documentation is quite confusing specifically the following bit:

When a package's name doesn't match the import name, you can install the package with the add-package comment above your imports.

The “comment above your imports” bit of text is a bit difficult to interpret and both me and another developer in our team presumed that it meant the magic comment goes above the associated import and not above all the imports. In my opinion this would make a bit more sense:

When a package's name doesn't match the import name, you can install the package with the add-package comment at the top of your codeblock.

Just a slight bit of feedback as I believe this wording could trip a couple of people up.

Thanks for commenting on that - we’ll update the docs to make this more clear