当我运行这个:
from firebase import firebase
from sanction import Client
client_pin = ''
client_id = 'valid_id'
client_secret = 'valid_secret'
request_token = 'state'
access_token = ''
query_url_wss = 'wss://developer-api.nest.com'
query_url_https = 'https://developer-api.nest.com'
auth_url = 'https://home.nest.com/login/oauth2?client_id=%s&state=%s' %(client_id, request_token)
access_token_url = 'https://api.home.nest.com/oauth2/access_token'
print('Visit the below link in a web browser to get an access PIN:\n')
print(auth_url)
client_pin = input('Enter PIN: ')
c = Client(
token_endpoint=access_token_url,
client_id=client_id,
client_secret=client_secret)
c.request_token(code = client_pin)
data = c.request('/devices')
print(data)我得到了这个输出(忽略这里的错误-这只是一个证明,客户端被创建和使用,并获得一个有效的令牌。这是目前获得access_token打印的唯一方法):
Visit the below link in a web browser to get an access PIN:
https://home.nest.com/login/oauth2?client_id=VALID_ID&state=state
Enter PIN: [ENTERED_A_VALID_PIN]
Traceback (most recent call last):
File "C:\py\nest_testing_sanction.py", line 29, in <module>
data = 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=[VALID_TOKEN]'在创建客户端类时,没有打印“客户端启动”。我对__init__.py做的任何事情都不会生效。它是否缓存在某个地方与股票版本?
__init__.py来源:http://pastebin.com/TksTyZT4
修改后的函数(如上面的错误输出所引用的__init__.py中所示):
class Client(object):
def __init__(self, auth_endpoint=None, token_endpoint=None,
resource_endpoint=None, client_id=None, client_secret=None,
token_transport=None):
assert token_transport is None or hasattr(token_transport, '__call__')
self.auth_endpoint = auth_endpoint
self.token_endpoint = token_endpoint
self.resource_endpoint = resource_endpoint
self.client_id = client_id
self.client_secret = client_secret
self.access_token = None
self.token_transport = token_transport or transport_query
self.token_expires = -1
self.refresh_token = None
print('Client initiated') # Added this line - not getting executed我还修改了这一功能(可能与上述相同或类似):
def request_token(self, parser=None, redirect_uri=None, **kwargs):
kwargs = kwargs and kwargs or {}
parser = parser or _default_parser
kwargs.update({
'client_id': self.client_id,
'client_secret': self.client_secret,
'grant_type': 'grant_type' in kwargs and kwargs['grant_type'] or \
'authorization_code'
})
if redirect_uri is not None:
kwargs.update({'redirect_uri': redirect_uri})
msg = urlopen(self.token_endpoint, urlencode(kwargs).encode(
'utf-8'))
data = parser(msg.read().decode(msg.info().get_content_charset() or
'utf-8'))
for key in data:
setattr(self, key, data[key])
if hasattr(self, 'expires_in'):
try:
# python3 dosn't support long
seconds = long(self.expires_in)
except:
seconds = int(self.expires_in)
self.token_expires = mktime((datetime.utcnow() + timedelta(
seconds=seconds)).timetuple())
#
# I added all these prints and the return - no dice
#
print('***************************************************')
print('Access Token: %s' %self.access_token)
print('Token Life: %s' %self.token_expires)
print('***************************************************')
return self.access_token我唯一能想到的是,有另一个版本的文件正在被使用,但我不知道它可能在哪里,如果是这样的话。
发布于 2014-10-21 18:24:28
可能有一个过时的.pyc文件需要删除。根据您运行代码的方式,它可能会被编译成存储在.pyc文件中的字节码。但是,当您对.py中的源代码进行更改时,它不会在重新运行时覆盖现有的.pyc。如果您的代码位于要导入的模块中,则会发生这种情况。寻找__init__.pyc并删除那个坏男孩。
编辑,聊天后我们发现:
导入的C:\Python34\lib\site-packages**sanction-0.4.1-py3.4.egg\sanction\__init__.py位于C:\Python34\lib\site-packages**sanction\__init__.py.,而正在编辑的__init__.py位于C:\Python34\lib\site-packages**sanction\__init__.py.
sanction-0.4.1-py3.4.egg实际上不是一个文件夹,而是一个文件,由于某些原因(未知,但可能是由于安装错误)而在导入中保持优先级。
https://stackoverflow.com/questions/26493592
复制相似问题