2

I am developing an POC it is required for a approach evaluation. I have python, venv, apache beam and gcloud installed in my Mac. And, i have logged in gcloud pupsub.

the following code, creates an subscription my Pubsub topic and read the message from PubSub.

Steps:

  1. execute the code
  2. go to gcloud poubsub topic and publish a simple message
  3. the code reads the message and creates an out put file

but no luck, i am getting the following error: AttributeError: 'SubscriberGrpcTransport' object has no attribute 'channel'

Code:

def run(argv=None): 
parser = argparse.ArgumentParser() 
parser.add_argument( 
   '--topic', 
   type=str, 
   help='Pub/sub topic to read from') 
parser.add_argument( 
   '--output', 
   help=('Output local filename')) 
args, pipeline_args = parser.parse_known_args(argv) 
options = PipelineOptions(pipeline_args) 
options.view_as(SetupOptions).save_main_session = True 
options.view_as(StandardOptions).streaming = True 

p = beam.Pipeline(options=options) 
(p | 'Read from PubSub' >> beam.io.ReadStringsFromPubSub(topic=args.topic) 
   | 'Write to file' >> beam.io.WriteToText(args.output) 
) 
result = p.run() 
result.wait_until_finish() 

if __name__ == '__main__': 
run() 

and ref the video: https://www.youtube.com/watch?v=I1JUtoDHFcg 9:13th mintus.

Please pass your expert help to fix the issue.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sen
  • 45
  • 1
  • 8
  • What runner are you using, and what is the full stack trace of the error you are seeing? – danielm Feb 08 '21 at 18:33
  • I am using DirectRunner. python hello-beam2.py --project fiery-azimuth-191807 --input_topic 'projects/fiery-azimuth-191807/topics/test1' --runner DirectRunner – sen Feb 09 '21 at 04:14

2 Answers2

2

Seems to be a case of missing dependencies.

pip install 'apache-beam[gcp]'

fixed it for me. Other dependencies I had installed previously:

pip install google-cloud-pubsub
pip install google-apitools
Zain Qasmi
  • 345
  • 2
  • 14
1

I'm also in a POC so I am trying Apache Beam on Colabs. I had no problems with batch pipelines although I've got the same error on Google Colab running a streaming pipeline (PubSub)

ERROR:apache_beam.runners.direct.executor:Exception at bundle <apache_beam.runners.direct.bundle_factory._Bundle object at 0x7f3347bf91c8>, due to an exception. Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/apache_beam/runners/direct/transform_evaluator.py", line 694, in _read_from_pubsub self._sub_name, max_messages=10, return_immediately=True) File "/usr/local/lib/python3.6/dist-packages/google/cloud/pubsub_v1/_gapic.py", line 40, in <lambda> fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw) # noqa File "/usr/local/lib/python3.6/dist-packages/google/pubsub_v1/services/subscriber/client.py", line 1069, in pull "If the `request` argument is set, then none of " ValueError: If the `request` argument is set, then none of the individual field arguments should be set. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/apache_beam/runners/direct/executor.py", line 382, in call finish_state) File "/usr/local/lib/python3.6/dist-packages/apache_beam/runners/direct/executor.py", line 423, in attempt_call result = evaluator.finish_bundle() File "/usr/local/lib/python3.6/dist-packages/apache_beam/runners/direct/transform_evaluator.py", line 706, in finish_bundle data = self._read_from_pubsub(self.source.timestamp_attribute) File "/usr/local/lib/python3.6/dist-packages/apache_beam/runners/direct/transform_evaluator.py", line 700, in _read_from_pubsub sub_client.api.transport.channel.close() AttributeError: 'SubscriberGrpcTransport' object has no attribute 'channel'

AttributeError: 'SubscriberGrpcTransport' object has no attribute 'channel'

I installed Apache Beam on my MAC using miniconda

conda create -n apache-beam-streaming python=3.7
conda activate apache-beam-streaming
pip install apache-beam[gcp]

Using DirectRunner the same code runs without problems

python streaming.py --runner DirectRunner
Antonio Cachuan
  • 475
  • 1
  • 9
  • 22