TypeError:字符映射必须返回integer、None或unicode

2024-10-04 03:24:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让site in a dropbox工作主要是想知道如何在appengine上使用dropbox。在

Python: c: \程序文件(x86)\Google\Google_appengine>;python Python 2.7.3(默认值,2012年4月10日,23:31:26)[MSC v.1500 32位(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_回调中 访问令牌=models.Site.dropbox_身份验证。获取“访问”令牌(令牌,“”)

无法将此部分转换为unicode。关于如何开始使用appengine上的dropbox有什么想法或其他建议吗?提前谢谢。在


Tags: inpyselftokenauthhandlerslineoauth
2条回答

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

我签出了siteindropbox代码,并查看了key值的来源,除非有什么恶作剧,否则只有当您的dropbox.auth.Authenticator实例的self.consumer.secret是unicode或当dropbox_auth_callback中的token.secret是unicode时,它才会是unicode。我不认为这两种情况是如何发生的。在创建Authenticator时,您是否碰巧传入了一个自定义的configdict,还是遵循了使用Authenticator.load_config的模式,就像siteinadropbox/models/site.pytest/dbtools.py中所做的那样?在

我改了hmac.py,如果在调用translate之前是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))
       ...

相关问题 更多 >