简体   繁体   English

在Raspberry Pi 3和Python上使用Google Assistant库时出错(不接受凭据)

[英]Error using Google Assistant Library with Raspberry Pi 3 and Python (Credentials not accepted)

I successfully managed to get Google's Assistant working on my Raspberry Pi 3. It works by using 我成功地使Google的Assistant在我的Raspberry Pi 3上运行。

google-assistant-demo --d device_id1234

Now I want to get access with python to turn on/off an LED when a certain command is recognized. 现在,我想使用python进行访问,以在识别特定命令时打开/关闭LED。 Unfortunately the page I followed isn't free, so I can't provide a link. 不幸的是,我关注的页面不是免费的,因此无法提供链接。 The problematic part of my code is the following: 我的代码中有问题的部分如下:

def main():
   parser = argparse.ArgumentParser(
       formatter_class=argparse.RawTextHelpFormatter)
   parser.add_argument('--credentials', type=existing_file,
                       metavar='OAUTH2_CREDENTIALS_FILE',
                       default=os.path.join(
                           os.path.expanduser('~/.config'),
                           'google-oauthlib-tool',
                           'credentials.json'
                       ),
                       help='Path to store and read OAuth2 credentials')
   args = parser.parse_args()


   with open(args.credentials, 'r') as f:
       credentials = google.oauth2.credentials.Credentials(token=None,
                                                           **json.load(f))

       with Assistant(credentials) as assistant:
           print("Warte auf Hotword")
           for event in assistant.start():
               process_event(event, assistant)

and when I run the script by 当我运行脚本时

python assistant.py --credentials client_secret_blabla.json

it throws the error 引发错误

Traceback (most recent call last):
   File "assistant.py", line 137, in <module>
      main()
   File "assistant.py", line 128, in main
      **json.load(f)
TypeError: __init__() got an unexpected keyword argument 'installed'

I tried to reinstall everything and also redownloaded the json file. 我试图重新安装所有内容,还重新下载了json文件。 Obviously the json doesn't get recognized properly, but I don't have any clue what to do. 显然,无法正确识别json,但是我不知道该怎么做。 My JSON looks like this: 我的JSON看起来像这样:

{"installed":{"client_id":"XXX.apps.googleusercontent.com","project_id":"dotted-nature-182957","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"XXX","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

here is what the Credentials class is expecting: http://google-auth.readthedocs.io/en/latest/reference/google.oauth2.credentials.html 以下是凭据类的期望: http : //google-auth.readthedocs.io/zh_CN/latest/reference/google.oauth2.credentials.html

I hope you guys can help me with this. 我希望你们能帮助我。 Thanks a lot in advance! 在此先多谢!

I just figured it out. 我只是想通了。 The problem was that I was using the wrong json file. 问题是我使用了错误的json文件。 I find the documentation kind of unclear concerning that. 我发现与此有关的文档种类不清楚。 The JSON file you have to hand over to the python script is the one which is downloaded when executing 您必须移交给python脚本的JSON文件是执行时下载的JSON文件

google-oauthlib-tool --client-secrets /home/pi/PREVIOUSLYDOWNLOADEDJSON.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless

which is located at /home/pi/.config/google-oauthlib-tool/ in default. 默认情况下位于/home/pi/.config/google-oauthlib-tool/。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到版本的Google助理图书馆Raspberry Pi - Could not find version google-assistant-library Raspberry Pi Raspberry Pi Google Assistant上的Google自定义设备操作出错 - Google Custom Device Action Giving Error on Raspberry Pi Google Assistant 在树莓派中安装谷歌助手 sdk 时出现 .async 语法错误 - .async syntax error while installing google assistant sdk in raspberry Pi Raspberry Pi Python SNMP库错误 - Raspberry Pi Python SNMP library error Raspberry Pi 3 上的 Google Assistant 分段错误 - Google Assistant on Raspberry Pi 3 Segmentation fault 带有 Raspberry Pi 的 RGB 矩阵上的 Google Assistant - Google Assistant on rgb matrix with Raspberry Pi 使用 AIY 语音套件和 Raspberry Pi 运行“assistant_library_demo.py”时出现分段错误 - Segmentation fault when running "assistant_library_demo.py" using the AIY voice kit and Raspberry Pi Raspberry Pi Python程序第一行错误/ Python库错误 - Raspberry Pi Python Program First Line Error/Python Library Error Python 线程错误 - 使用 Raspberry Pi - Python Threading Error - Using Raspberry Pi Raspberry Pi 3上的Google Assistant-运行示例代码-错误对等证书无法使用给定的CA证书进行身份验证 - Google Assistant on Raspberry Pi 3 - Running sample code - error Peer certificate cannot be authenticated with given CA certificates
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM