使用Mega模块命令的预期字符串或缓冲区

时间:2015-04-17 23:06:15

标签: python error-handling

当我执行mega.login(email,password)

时出现以下错误
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mega\mega.py", line 26, in login
    instance.login_user(email, password)
  File "mega\mega.py", line 32, in login_user
    resp = self.api_request({'a': 'us', 'user': email, 'uh': uh})
  File "mega\mega.py", line 87, in api_request
    json_resp = json.loads(req.text)
  File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer

注意文件req.text不是我的,但我认为它与mega或json模块有关。另外,我从GitHub抓取了mega模块https://github.com/richardasaurus/mega.py 谢谢你帮助我: - )

1 个答案:

答案 0 :(得分:0)

当值不是字符串时会发生此错误,例如None

在您的情况下,这意味着emailpasswordNone

示例:

>>> import json
>>> json.loads(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer