如本页所述,我无法使用模块 contextIO ....
https://github.com/contextio/Python-ContextIO
我在希望看到电子邮件内容的地方收到错误消息。
import contextio as c
CONSUMER_KEY = 'dummy_key'
CONSUMER_SECRET = 'dummy_secret'
context_io = c.ContextIO(
consumer_key=CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET
)
accounts = context_io.get_accounts(email='dummy.email@gmail.com')
params = {
'id': 'dummy_id'
}
account = c.Account(context_io, params)
params = {
'message_id': 'dummy_message_id'
}
message = c.Message(account, params)
message.get()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "contextio/__init__.py", line 1721, in get
self.__init__(self.parent, self._request_uri('', params=params))
File "contextio/__init__.py", line 481, in _request_uri
uri, method=method, params=params, headers=headers, body=body
File "contextio/__init__.py", line 481, in _request_uri
uri, method=method, params=params, headers=headers, body=body
File "contextio/__init__.py", line 150, in _request_uri
self._handle_request_error(response)
File "contextio/__init__.py", line 185, in _handle_request_error
response_json = response.json()
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 638, in json
return json.loads(self.text or self.content, **kwargs)
File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 413, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 420, in raw_decode
raise JSONDecodeError("No JSON object could be decoded", s, idx)
simplejson.decoder.JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
我怎么知道这个错误是否是由于作为消息对象返回的 NULL 引起的?什么是 NoneType?
>>> type(message)
<class 'contextio.Message'>
>>> dir(message)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_request_uri', '_uri_for', 'addresses', 'base_uri', 'body', 'date', 'date_indexed', 'delete', 'email_message_id', 'facebook_headers', 'files', 'flags', 'folders', 'get', 'get_body', 'get_flags', 'get_folders', 'get_headers', 'get_source', 'get_thread', 'gmail_message_id', 'gmail_thread_id', 'headers', 'keys', 'list_headers', 'message_id', 'parent', 'person_info', 'post', 'post_flag', 'post_folder', 'put_folders', 'sanitize_params', 'source', 'sources', 'subject', 'thread']
>>> type(message.subject)
<type 'NoneType'>
为什么即使我提供了正确的凭据,我的代码也没有返回任何内容?