Python 属性错误:';流线型PullFuture';对象没有属性';打开';
我正在尝试编写一个作业,从订阅服务器读取消息并将其输出到bigquery。 使用的Python版本是3.6 我在执行代码时收到如下错误:Python 属性错误:';流线型PullFuture';对象没有属性';打开';,python,python-3.x,google-cloud-pubsub,Python,Python 3.x,Google Cloud Pubsub,我正在尝试编写一个作业,从订阅服务器读取消息并将其输出到bigquery。 使用的Python版本是3.6 我在执行代码时收到如下错误: Traceback (most recent call last): File "subscriber.py", line 73, in <module> receive_data(project_id, subscription_name ) File "subscriber.py", line 59, in receive_da
Traceback (most recent call last):
File "subscriber.py", line 73, in <module>
receive_data(project_id, subscription_name )
File "subscriber.py", line 59, in receive_data
future = subscription.open(callback)
AttributeError: 'StreamingPullFuture' object has no attribuate 'open'
根据谷歌文档,我看到导入的包是pubsub_v1,所以我用
从google.cloud导入pubsub_v1
但即使在这些变化之后,似乎也没有任何效果
还试图对requirements.txt进行更改,因为这似乎是版本问题。
Current requirements.txt如下所示:
cachetools==3.1.1
certifi==2019.9.11
chardet==3.0.4
google-api-core==1.14.3
google-auth==1.6.3
google-cloud-bigquery==1.20.0
google-cloud-core==1.0.3
google-cloud-pubsub==1.0.2
google-resumable-media==0.4.1
googleapis-common-protos==1.6.0
grpc-google-iam-v1==0.12.3
grpcio==1.24.1
idna==2.8
protobuf==3.10.0
pyasn1==0.4.7
pyasn1-modules==0.2.7
pytz==2019.3
requests==2.22.0
rsa==4.0
six==1.12.0
urllib3==1.25.6
有人可以指导吗?订阅者.subscribe(subscription\u path,callback=callback)调用本身返回未来的对象,不需要单独的
.open()
调用。只需将该结果分配给未来:
future = subscriber.subscribe(subscription_path, callback=callback)
print('Listening for messages on {}'.format(subscription_path))
try:
future.result()
except Exception as e:
print(
'Listening for messages on {} threw an Exception: {}'.format(
subscription_name, e))
raise
有,您已经使用
subscriber.subscribe()
设置了订阅subscriber.subscribe(subscription\u path,callback=callback)
调用本身返回未来对象,不需要单独的.open()
调用。只需将该结果分配给未来:
future = subscriber.subscribe(subscription_path, callback=callback)
print('Listening for messages on {}'.format(subscription_path))
try:
future.result()
except Exception as e:
print(
'Listening for messages on {} threw an Exception: {}'.format(
subscription_name, e))
raise
有,您已经使用
subscriber.subscribe()
设置了订阅。您希望subscription.open(callback)
做什么?您已经使用subscriber.subscribe(subscription\u path,callback=callback)
对订阅进行了回调,并且该调用已经为您提供了未来。您希望subscription.open(callback)
做什么?您已经使用subscriber.subscribe(subscription\u path,callback=callback)
对订阅进行了回调,并且该调用已经为您提供了未来。