gpt4 book ai didi

python - 通过 Nest 的 Oauth pin-auth session 获取 Firebase 数据时遇到问题

转载 作者:行者123 更新时间:2023-11-30 23:19:23 24 4
gpt4 key购买 nike

基本脚本:

from sanction import Client
# client_id & client_secret are omitted but are valid

client_pin = input('Enter PIN:')

access_token_url = 'https://api.home.nest.com/oauth2/access_token'

c = Client(
token_endpoint=access_token_url,
client_id=client_id,
client_secret=client_secret)

c.request_token(code = client_pin)

[See edits for history]

运行c.request('/devices')返回:

Traceback (most recent call last):
File "C:\py\nest_testing_sanction.py", line 36, in <module>
c.request("/devices")
File "C:\Python34\lib\site-packages\sanction-0.4.1-py3.4.egg\sanction\__init__.py", line 169, in request
File "C:\Python34\lib\site-packages\sanction-0.4.1-py3.4.egg\sanction\__init__.py", line 211, in transport_query
File "C:\Python34\lib\urllib\request.py", line 258, in __init__
self.full_url = url
File "C:\Python34\lib\urllib\request.py", line 284, in full_url
self._parse()
File "C:\Python34\lib\urllib\request.py", line 313, in _parse
raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'None/devices?access_token=c.[some long session token]'

鉴于输出,我似乎需要输入通用 URL,因此我尝试了 c.request('wss://developer-api.nest.com'):

Traceback (most recent call last):
File "C:\py\nest_testing_sanction.py", line 36, in <module>
data = c.request(query_url)
File "C:\Python34\lib\site-packages\sanction-0.4.1-py3.4.egg\sanction\__init__.py", line 171, in request
File "C:\Python34\lib\urllib\request.py", line 153, in urlopen
return opener.open(url, data, timeout)
File "C:\Python34\lib\urllib\request.py", line 455, in open
response = self._open(req, data)
File "C:\Python34\lib\urllib\request.py", line 478, in _open
'unknown_open', req)
File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 1257, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: nonewss>

我还尝试了 https 如下:

enter image description here - 相同的结果

相比之下,这有效(对于 firebase.io 虚拟设备):

firebase = firebase.FirebaseApplication('https://nesttest.firebaseio.com', None)
thermostat_result = firebase.get('/devices', 'thermostats')

最佳答案

在Python中我会使用类似sanction的东西为了让事情变得简单。您应该能够使用以下代码让它与 Nest API 一起使用:(未经测试,使用 token 流而不是 pin 流)

from sanction.client import Client

# instantiating a client to get the auth URI
c = Client(auth_endpoint="https://home.nest.com/login/oauth2",
client_id=config["nest.client_id"])

# instantiating a client to process OAuth2 response
c = Client(token_endpoint="https://api.home.nest.com/oauth2/access_token",
client_id=config["nest.client_id"],
client_secret=config["nest.client_secret"])

该库有详细的文档记录,因此如果缺少某些内容,您应该能够从这里找到。

关于python - 通过 Nest 的 Oauth pin-auth session 获取 Firebase 数据时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26105065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com