I am trying to implement a functionality in python that publishes message into google cloud pub/sub which I am able to perform well when running in my local but on pipedream it is giving me the error read ECONNRESET. I guess it is occurring because of importing google.cloud package. I confirmed the same by running a simple hello world program with the google cloud import. Attaching the code snippet and output below:
import os
from google.cloud import pubsub_v1
def handler(pd: “pipedream”):
credentials_path =pd.steps[“trigger”][“event”]
os.environ[‘GOOGLE_APPLICATION_CREDENTIALS’] = credentials_path
publisher = pubsub_v1.PublisherClient()
topic_path = ‘projects/my-project-1909-363003/topics/my-topic’
data = ‘Msg from Pipedream’
data = data.encode(‘utf-8’)
attributes = {
‘FName3’: ‘Acco’,
}
future = publisher.publish(topic_path, data, **attributes)
print(f’published message id {future.result()}')
pierce
(Pierce)
September 29, 2022, 5:03pm
2
Hi @radhikakondapaneni
Have you tried using the Pipedream comment import system for Python packages with different package names than it’s module name?
I believe google.cloud pages have this pattern, following this guide might solve the issue:
@pierce I have tried that too . It gave me the same error. Also the package I need is pub sub from google-cloud.
pierce
(Pierce)
September 29, 2022, 6:00pm
4
Hi @radhikakondapaneni ,
Could you try using this import statement?
# pipedream add-package google-cloud-pubsub
from google.cloud import pubsub_v1
From the Google PubSub docs , it looks like the PIP package name is google-cloud-pubsub
not google-cloud-pubsub_v1
.
I was able to install that package in a Python code step.
@pierce even then it is giving me same error
pierce
(Pierce)
September 30, 2022, 1:32pm
6
I wonder if your workflow’s environment is somehow in a bad state from the initial import.
Could you try starting a brand new workflow, and only adding one Python step with that import statement I shared?