Python 3.x Google PubSub订户与Google SDM API(嵌套设备)的问题
所以,我被卡住了。这可能会很长,因为我想确定达到这一点所做的全部(或大部分)工作: 背景:想为Raspberry PI创建一个应用程序,该应用程序可以访问嵌套的设备套件(门铃、恒温器等)并对其进行操作。我现在在笔记本电脑上的Ubuntu虚拟机上做这件事 我所做的:Python 3.x Google PubSub订户与Google SDM API(嵌套设备)的问题,python-3.x,google-cloud-platform,oauth,publish-subscribe,google-sdm-api,Python 3.x,Google Cloud Platform,Oauth,Publish Subscribe,Google Sdm Api,所以,我被卡住了。这可能会很长,因为我想确定达到这一点所做的全部(或大部分)工作: 背景:想为Raspberry PI创建一个应用程序,该应用程序可以访问嵌套的设备套件(门铃、恒温器等)并对其进行操作。我现在在笔记本电脑上的Ubuntu虚拟机上做这件事 我所做的: 按照谷歌提供的步骤创建了一个设备访问项目 还创建了一个GCP项目(与上面不同),以便能够设置OAuth和订阅设置 设备访问项目使用GCP项目中的OAuth,即设备访问项目有一个引用GCP项目OAuth的字段 完成设备访问项目步骤,通过
projtest - listening for messages on: projects/nestcontroller-299520/subscriptions/NestControlSub
subscription_id : NestControlSub
Background thread did not exit.
ERROR:root:Exception in callback <bound method ResumableBidiRpc._on_call_done of <google.api_core.bidi.ResumableBidiRpc object at 0x7f042ae47fa0>>: ValueError('Cannot invoke RPC: Channel closed!')
这立即导致以下“无效授权:未找到帐户”错误,该错误不断重复,直到我取消脚本
ERROR:grpc._plugin_wrapping:AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x7f7188d17d30>" raised exception!
Traceback (most recent call last):
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/grpc/_plugin_wrapping.py", line 77, in __call__
self._metadata_plugin(
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/auth/transport/grpc.py", line 86, in __call__
callback(self._get_authorization_headers(context), None)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/auth/transport/grpc.py", line 72, in _get_authorization_headers
self._credentials.before_request(
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/auth/credentials.py", line 133, in before_request
self.refresh(request)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/oauth2/service_account.py", line 361, in refresh
access_token, expiry, _ = _client.jwt_grant(request, self._token_uri, assertion)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/oauth2/_client.py", line 153, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/oauth2/_client.py", line 124, in _token_endpoint_request
_handle_error_response(response_body)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/oauth2/_client.py", line 60, in _handle_error_response
raise exceptions.RefreshError(error_details, response_body)
google.auth.exceptions.RefreshError: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed non-terminating stream error 503 Getting metadata from plugin failed with error: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed recoverable stream error 503 Getting metadata from plugin failed with error: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
INFO:google.api_core.bidi:Re-established stream
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed non-terminating stream error 503 Getting metadata from plugin failed with error: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed recoverable stream error 503 Getting metadata from plugin failed with error: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
错误:grpc.\u plugin\u wrapping:AuthMetadataPluginCallback“”引发异常!
回溯(最近一次呼叫最后一次):
文件“/home/christian/PythonProjects/google cloud pubsub/venv/lib/python3.8/site packages/grpc/_plugin_wrapping.py”,第77行,在调用中__
self.\u元数据\u插件(
文件“/home/christian/PythonProjects/google cloud pubsub/venv/lib/python3.8/site packages/google/auth/transport/grpc.py”,第86行,in_ucall__
回调(self.\u获取\u授权\u头(上下文),无)
文件“/home/christian/PythonProjects/google cloud pubsub/venv/lib/python3.8/site packages/google/auth/transport/grpc.py”,第72行,在“获取授权”标题中
自我认证。在请求之前(
文件“/home/christian/PythonProjects/google cloud pubsub/venv/lib/python3.8/site packages/google/auth/credentials.py”,第133行,在请求之前
自我刷新(请求)
文件“/home/christian/PythonProjects/google cloud pubsub/venv/lib/python3.8/site packages/google/oauth2/service_account.py”,第361行,刷新
访问令牌,到期,客户端.jwt\u授权(请求,自.\u令牌\u uri,断言)
jwt_grant中的文件“/home/christian/PythonProjects/google cloud pubsub/venv/lib/python3.8/site packages/google/oauth2/_client.py”,第153行
响应\数据=\令牌\端点\请求(请求,令牌\ uri,正文)
文件“/home/christian/PythonProjects/google cloud pubsub/venv/lib/python3.8/site packages/google/oauth2/_client.py”,第124行,在_token_endpoint_请求中
_句柄错误响应(响应体)
文件“/home/christian/PythonProjects/google cloud pubsub/venv/lib/python3.8/site packages/google/oauth2/\u client.py”,第60行,在“handle\u error\u response”中
引发异常。刷新错误(错误详细信息、响应正文)
google.auth.exceptions.RefreshError:('invalid_grant:invalid grant:account not found','{“error”:“invalid_grant”,“error_description”:“invalid grant:account not found”})
信息:google.cloud.pubsub\u v1.subscriber.\u协议.流式传输\u pull\u管理器:观察到的非终止流错误503从插件获取元数据失败,错误为:('invalid\u grant:invalid grant:account not found','{“error”:“invalid\u grant”,“error\u description”:“invalid grant:account not found”})
信息:google.cloud.pubsub\u v1.subscriber.\u协议.流媒体\u pull\u管理器:观察到的可恢复流错误503从插件获取元数据失败,错误为:('invalid\u grant:invalid grant:account not found','{“error”:“invalid\u grant”,“error\u description”:“invalid grant:account not found”})
信息:google.api_core.bidi:重建流
信息:google.cloud.pubsub\u v1.subscriber.\u协议.流式传输\u pull\u管理器:观察到的非终止流错误503从插件获取元数据失败,错误为:('invalid\u grant:invalid grant:account not found','{“error”:“invalid\u grant”,“error\u description”:“invalid grant:account not found”})
信息:google.cloud.pubsub\u v1.subscriber.\u协议.流\u拉\u管理器:观察到可恢复流错误503从插件获取元数据失败,错误为:('invalid\u grant:invalid
project_id = 'nestcontroller-299520'
subscription_id = 'NestControlSub'
topic_id = 'projects/sdm-prod/topics/enterprise-5a0f7c4e-d20d-4e56-968d-c6239936a3b0'
def callback(message, event):
logger.info(message)
event.set()
subscriber = pubsub_v1.SubscriberClient()
event = Event()
def callback_wrapper(message):
callback(message, event)
future = subscriber.subscribe('subscription/path', callback=callback_wrapper)
event.wait()
logger.exception('Got event. Shutting down.')
future.cancel()
exit(1)
ERROR:grpc._plugin_wrapping:AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x7f7188d17d30>" raised exception!
Traceback (most recent call last):
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/grpc/_plugin_wrapping.py", line 77, in __call__
self._metadata_plugin(
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/auth/transport/grpc.py", line 86, in __call__
callback(self._get_authorization_headers(context), None)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/auth/transport/grpc.py", line 72, in _get_authorization_headers
self._credentials.before_request(
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/auth/credentials.py", line 133, in before_request
self.refresh(request)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/oauth2/service_account.py", line 361, in refresh
access_token, expiry, _ = _client.jwt_grant(request, self._token_uri, assertion)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/oauth2/_client.py", line 153, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/oauth2/_client.py", line 124, in _token_endpoint_request
_handle_error_response(response_body)
File "/home/christian/PythonProjects/google-cloud-pubsub/venv/lib/python3.8/site-packages/google/oauth2/_client.py", line 60, in _handle_error_response
raise exceptions.RefreshError(error_details, response_body)
google.auth.exceptions.RefreshError: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed non-terminating stream error 503 Getting metadata from plugin failed with error: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed recoverable stream error 503 Getting metadata from plugin failed with error: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
INFO:google.api_core.bidi:Re-established stream
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed non-terminating stream error 503 Getting metadata from plugin failed with error: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed recoverable stream error 503 Getting metadata from plugin failed with error: ('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')