Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Google PubSub订户与Google SDM API(嵌套设备)的问题_Python 3.x_Google Cloud Platform_Oauth_Publish Subscribe_Google Sdm Api - Fatal编程技术网

Python 3.x Google PubSub订户与Google SDM API(嵌套设备)的问题

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的字段 完成设备访问项目步骤,通过

所以,我被卡住了。这可能会很长,因为我想确定达到这一点所做的全部(或大部分)工作:

背景:想为Raspberry PI创建一个应用程序,该应用程序可以访问嵌套的设备套件(门铃、恒温器等)并对其进行操作。我现在在笔记本电脑上的Ubuntu虚拟机上做这件事

我所做的:

  • 按照谷歌提供的步骤创建了一个设备访问项目
  • 还创建了一个GCP项目(与上面不同),以便能够设置OAuth和订阅设置
  • 设备访问项目使用GCP项目中的OAuth,即设备访问项目有一个引用GCP项目OAuth的字段
  • 完成设备访问项目步骤,通过浏览器页面授予权限,直至我创建并使用授权代码,并获得第一个访问令牌。我能够执行CURL命令来检索嵌套设备特征,甚至可以执行rtspurl来访问相机流
  • 因此,我已经完成了一半,因为我可以通过使用OAuth访问令牌与设备(RESTAPI)交互。但我想做的是能够对来自设备的事件做出反应,这需要PubSub的交互性。这就是我被困的地方

    额外步骤:我还在GCP凭据中创建了一个服务帐户,因为我在文档中看到可能需要它,而GOOGLE算法需要一个GOOGLE_APPLICATION_Credentials环境变量,该变量包含服务帐户的已下载凭据,并包含到json文件中。所以检查

  • 在设置设备访问项目时,创建了一个PubSub主题。在GCP控制台中,我为GCP项目创建了相应的订阅,并手动将其引用到作为设备访问项目一部分创建的主题(上面的步骤)
  • 文档中提到,第一次通过RESTAPI与OAuth访问令牌交互时,pubsub功能就可用了。注意:我可以从GCP控制台中的PubSub订阅页面确认“查看消息”。我能够“拉”消息,并看到消息出现在订阅中。我知道,通过提取消息,我暂时阻止它们出现在其他队列中,但我想检查消息是否能够在订阅中填充
  • 嗯。因此,不,我想编写代码来访问pubsub订阅,并围绕这些事件消息创建我的应用程序(或其中的一部分)。这就是我被困了两天的地方

    我已经基于google提供的方法创建了一个python脚本(我不介意包含ID,因为这不是私有的)

    结果如下:

    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"}')