执行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 https://github.com/richardasaurus/mega.py抢购了mega模块
感谢您的帮助:-)
最佳答案
如果该值不是字符串,例如None
,则会发生此错误。
在您的情况下,这意味着email
或password
是None
。
例:
>>> 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