当我运行时:
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]'
创建Client类时,我没有打印出“客户端启动”。我对__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
我唯一能想到的是该文件的另一个版本正在被使用,但我不知道它可能在哪里,或者如果是这种情况。
答案 0 :(得分:1)
可能存在需要删除的陈旧.pyc文件。根据您运行代码的方式,可能会将其编译为存储在.pyc文件中的字节代码。但是,当您在.py中更改源时,它在重新运行时不会覆盖现有的.pyc。如果您的代码位于要导入的模块中,则会发生这种情况。寻找__init__.pyc
并删除那个坏男孩。
编辑,聊天后我们发现:
导入的 __init__.py
位于C:\ Python34 \ lib \ site-packages \ sanction-0.4.1-py3.4.egg \ sanction \ __ init__.py正在编辑的__init__.py
位于C:\ Python34 \ lib \ site-packages \ 制裁 \ __ init __。py。
sanction-0.4.1-py3.4.egg
实际上并不是一个文件夹,而是一个文件,并且出于某种原因在导入时保持优先级(未知,但可能是由于安装错误)。