2

我正在尝试在 Dropbox 中获取站点,主要是为了弄清楚如何在 appengine 上使用 Dropbox。

python: c:\Program Files (x86)\Google\google_appengine>python Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win 32

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
    handler.get(*groups)
  File "C:\youiestsiteinadropbox\siteinadropbox\handlers\dropboxhandlers.py", line 38, in new_f
    f(self, *args, **kwargs)
  File "C:\youiestsiteinadropbox\siteinadropbox\handlers\dropboxhandlers.py", line 65, in get
    self.dropbox_auth_callback(self.site)
  File "C:\youiestsiteinadropbox\siteinadropbox\handlers\dropboxhandlers.py", line 118, in dropbox_auth_callback
    access_token = models.Site.dropbox_auth.obtain_access_token(token, "")
  File "C:\youiestsiteinadropbox\dropbox\auth.py", line 177, in obtain_access_token
    self.oauth_request.sign_request(self.signature_method_hmac_sha1, self.consumer, token)
  File "C:\youiestsiteinadropbox\oauth\oauth.py", line 259, in sign_request
    self.build_signature(signature_method, consumer, token))
  File "C:\youiestsiteinadropbox\oauth\oauth.py", line 263, in build_signature
    return signature_method.build_signature(self, consumer, token)
  File "C:\youiestsiteinadropbox\oauth\oauth.py", line 634, in build_signature
    hashed = hmac.new(key, raw, sha)
  File "C:\Python27\lib\hmac.py", line 133, in new
    return HMAC(key, msg, digestmod)
  File "C:\Python27\lib\hmac.py", line 72, in __init__
    self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode

应用程序内的最后一次调用是:

文件“C:\youiestsiteinadropbox\siteinadropbox\handlers\dropboxhandlers.py”,第 118 行,在 dropbox_auth_callback access_token = models.Site.dropbox_auth.obtain_access_token(token, "")

将此部分转换为 unicode 并没有多大成功。关于如何在 appengine 上开始使用 Dropbox 的任何想法或其他指示?提前致谢。

4

2 回答 2

3

我从来没有使用过siteinadropbox,但这个错误的最终原因是key最后一个变量是一个unicode对象,而代码期望它是一个str对象。我知道,这不是一条特别有用的信息。

我检查了 siteinadropbox 代码并检查了该key值的来源,除非某处有恶作剧,否则只有当您的dropbox.auth.Authenticator实例self.consumer.secret是 unicode 或token.secretfromdropbox_auth_callback是 unicode 时,它​​才会是 unicode。粗略检查一下,我看不出这两种情况是如何发生的。config在创建 dict 时,您是否碰巧传入了自定义dict Authenticator,或者您是否遵循 using 的模式,如和示例Authenticator.load_config中所做的那样?siteinadropbox/models/site.pytest/dbtools.py

于 2012-07-09T15:59:15.330 回答
0

我修改了 hmac.py,如果在调用 tranlate 之前它是 unicode,则将 key 转换为 str 对象,并且它可以工作。

    # 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))
       ...
于 2013-05-17T07:24:18.990 回答