AttributeError: 'API' object has no attribute 'sso_token'
dieggsy opened this issue · 7 comments
Hm. In normal operation that error shouldn't be possible (self.sso_token
is set in API.__init__
, here).
Are you by chance pickling or otherwise serializing API objects into some sort of long-term storage, then trying to read them back out? If there were an API object from an older version of the library that was then trying to be read into the newer version of the library, that could cause an error like that.
If you're not serializing/pickling API objects (or some object that contains an API object), then I'd probably need to know more about the context in which the error is occurring - i.e. exactly what call is generating it.
Yep, I was pickling objects – solved!
As a side note, I'd recommend not pickling API
objects - they aren't designed to be long-lifed.
APIResult
objects are fine to pickle if you want to save the results of calls.
@ayust I'm just recently learning about all of this, thanks... I noticed results get automatically cached, could you explain how that works?
Also, I was curious what sqlite3.Binary is (used in evelink/cache/sqlite.py) – I can't seem to find any documentation for it anywhere (including the sqlite3 module page on python3 docs)
Sure!
Every response from the EVE API includes a "cache until" timestamp which indicates how long a client should wait before requesting the same thing again (because the value will only update every so often). By default the EVELink library uses an in-memory cache to remember the results from calls to the API. It automatically stores the results for as long as the EVE API recommends. When an API result is cached, if you make the same function call again, the result will be returned directly from the cache without needing to make an actual HTTP request to CCP's servers. Getting a result from the cache is a lot faster, since HTTP requests are really the slowest part of the API call.
However, because it's an in-memory cache, whenever your script/program exits, the cache is lost. Since some API calls can have cache times 15 minutes, an hour, or even more, you often want to be able to preserve the cached values across invocations of a script or restarts of a program. That's where the disk-based caches come in.
The best disk-based cache option is probably the SqliteCache
- it uses a SQLite file-based database to store the cached values on disk. To use it, just create a SqliteCache object and pass it as the cache
argument to the API
object constructor. Then EVELink will store all of its cached API call results in the path you provided.
As for sqlite3.Binary
- that's just one of the data types that SQLite offers when storing values in its database file. Using the "binary" type means that it will treat the data it receives as raw binary data rather than trying to format it as text, which is good, since we're storing binary pickled objects in it.
Woah, you answered questions I asked, questions I had but didn't ask, and questions I didn't even know I had. Thanks for the thorough explanation!