Google Cloud Platform Pub子-Python客户端不发布消息

时间:2018-07-03 21:25:37

标签: google-cloud-platform google-cloud-dataflow google-cloud-pubsub google-cloud-python

设置是这样的:

我已经设置了一个主题来接收消息,然后使用Pub/Sub to GCS Text Template设置了Dataflow管道,该管道将消息转储到GCS桶中的窗口文本文件中。效果很好-我最终在GCS中获得文件,其中包含使用主题上的“发布消息”按钮通过控制台发送的测试消息(注意,我以为它将保存消息的“数据”部分,但看起来像它只会保存邮件正文。但是我可以解决此问题。

问题:

我打算使用python客户端(最终从App Engine)向该主题发送消息...但是当我从本地计算机发送消息时,却无法正常工作。我正在使用pubsub_v1模块关注https://cloud.google.com/pubsub/docs/publisher中非常简单的示例。即使将批处理设置设置为1kb / 1s,我也无法成功发布。以后5分钟未响应,我仍然收到此错误:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/path/to/environment/lib/python2.7/site-packages/google/cloud/pubsub_v1/publisher/batch/thread.py", line 239, in monitor
    return self._commit()
  File "/path/to/environment/lib/python2.7/site-packages/google/cloud/pubsub_v1/publisher/batch/thread.py", line 204, in _commit
    self._messages,
  File "/path/to/environment/lib/python2.7/site-packages/google/cloud/pubsub_v1/gapic/publisher_client.py", line 325, in publish
    return self._publish(request, retry=retry, timeout=timeout)
  File "/path/to/environment/lib/python2.7/site-packages/google/api_core/gapic_v1/method.py", line 139, in __call__
    return wrapped_func(*args, **kwargs)
  File "/path/to/environment/lib/python2.7/site-packages/google/api_core/retry.py", line 260, in retry_wrapped_func
    on_error=on_error,
  File "/path/to/environment/lib/python2.7/site-packages/google/api_core/retry.py", line 195, in retry_target
    last_exc)
  File "/path/to/environment/lib/python2.7/site-packages/six.py", line 737, in raise_from
    raise value
RetryError: Deadline of 600.0s exceeded while calling <functools.partial object at 0x10662de68>, last exception: 503 Getting metadata from plugin failed with error: ('invalid_grant: Bad Request', u'{\n  "error" : "invalid_grant",\n  "error_description" : "Bad Request"\n}')

代码示例:

>>> from google.cloud import pubsub_v1
>>> BATCH_SETTINGS = pubsub_v1.types.BatchSettings(max_bytes=1024,max_latency=1)
>>> publisher = pubsub_v1.PublisherClient(BATCH_SETTINGS)
>>> topic_path = publisher.topic_path("my-project", "topic-name")
>>> publisher.publish(topic_path, b'first message from python 3:38:59')

更新: 部署我的应用程序后,在生产中一切正常。可以满足我的需求,但是仍然很高兴知道为什么在计算机上以调试模式在本地运行时它不起作用。

1 个答案:

答案 0 :(得分:1)

这是一个已知问题,如果正在运行python的环境的系统时钟不同步,您将无法进行身份验证。在不知道您正在运行哪种系统的情况下,很难知道如何同步时钟,但是您可以查看here了解更多详细信息。

相关问题