我试图在dropbox中找到一个站点,主要是想知道如何在appengine上使用dropbox。
python:c: \Program Files(x86)\Google\Google_appengine>pythonPython 2.7.3(默认,2012年4月10日,23:31:26)[MSC v.1500 32位(英特尔)]获胜32
Traceback (most recent call last):
File "C:Program Files (x86)Googlegoogle_appenginegoogleappengineextwebapp_webapp25.py", line 701, in __call__
handler.get(*groups)
File "C:youiestsiteinadropboxsiteinadropboxhandlersdropboxhandlers.py", line 38, in new_f
f(self, *args, **kwargs)
File "C:youiestsiteinadropboxsiteinadropboxhandlersdropboxhandlers.py", line 65, in get
self.dropbox_auth_callback(self.site)
File "C:youiestsiteinadropboxsiteinadropboxhandlersdropboxhandlers.py", line 118, in dropbox_auth_callback
access_token = models.Site.dropbox_auth.obtain_access_token(token, "")
File "C:youiestsiteinadropboxdropboxauth.py", line 177, in obtain_access_token
self.oauth_request.sign_request(self.signature_method_hmac_sha1, self.consumer, token)
File "C:youiestsiteinadropboxoauthoauth.py", line 259, in sign_request
self.build_signature(signature_method, consumer, token))
File "C:youiestsiteinadropboxoauthoauth.py", line 263, in build_signature
return signature_method.build_signature(self, consumer, token)
File "C:youiestsiteinadropboxoauthoauth.py", line 634, in build_signature
hashed = hmac.new(key, raw, sha)
File "C:Python27libhmac.py", line 133, in new
return HMAC(key, msg, digestmod)
File "C:Python27libhmac.py", line 72, in __init__
self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode
应用程序内的最后一个调用是:
dropbox_auth_callback中的文件"C:\youiestsiteinatropbox\siteinatropox\handlers\dropboxhandlers.py",第118行access_token=模型。Site.dropbox_auth.geourent_access_token(令牌,")
将此部分转换为unicode没有太大成功。关于如何在appengine上开始使用dropbox,有什么想法或其他建议吗?提前谢谢。
我从来没有使用过siteinadropbox,但这个错误的最终原因是最后一个变量中的key
是unicode
对象,而代码期望它是str
对象。我知道这不是一个特别有用的信息。
我检查了siteinadropbox代码,查看了key
值的来源,除非某个地方发生了恶作剧,否则只有当dropbox.auth.Authenticator
实例的self.consumer.secret
是unicode或dropbox_auth_callback
中的token.secret
是unicode时,它才会是unicode。粗略检查一下,我看不出这两种情况是怎么发生的。在创建Authenticator
时,您是否碰巧传入了自定义config
dict,或者您是否遵循了使用Authenticator.load_config
的模式,如siteinadropbox/models/site.py
和test/dbtools.py
示例中所做的那样?
我修改了hmac.py,在调用tranlate之前将key转换为str对象(如果它是unicode),它就可以工作了。
# hmac.py
...
71 key = key + chr(0) * (blocksize - len(key))
72 if type(key) == unicode:
73 key = key.encode()
74 self.outer.update(key.translate(trans_5C))
...