Tweepy API:什么是会话对象?

Tweepy API: What is a session object?

tweepy documentation uses an object named session that is not defined or explained anywhere in the documentation or the library's tests.

这个对象是什么,实例化它的例子是什么?

起初我猜它是 requests.Session() 的一个实例,但它没有附带 .set() 方法(或者在上下文中确实有意义):

>>> import requests
>>> hasattr(requests.Session(), 'set')
False

还有no class within tweepy定义了一个.set()方法。


文档摘录:

This call requests the token from twitter and returns to us the authorization URL where the user must be redirect to authorize us. Now if this is a desktop application we can just hang onto our OAuthHandler instance until the user returns back. In a web application we will be using a callback request. So we must store the request token in the session since we will need it inside the callback URL request. Here is a pseudo example of storing the request token in a session:

session.set('request_token', auth.request_token)

我认为文档说 session 可以是 any key/value 存储,但他们在这方面并不是特别清楚。所以 session 可以是任何东西,从 python 的内置 dict,到 redis,其他 nosql 存储等。实现细节和 class 对象 session实际上是留给用户的。

免责声明:我对 tweepy 知之甚少,完全承认这是一些猜测。我大约一年前用过一次,也有完全相同的问题。