Tweepy is a popular Python wrapper for Twitter API. Although it provides a lot of useful features where you don’t need to deal with JSON or XML directly, sometimes you would like to store all information you have requested. In other words, you would like to store the raw JSON returned by Tweepy.
For some reason, this feature is not supported by the current version of Tweepy (as of April 4, 2012). So, we need to hack a little bit to get the result. Indeed, this issue was discussed here. The current solution is to add the following code into “parsers.py” of the source code of Tweepy:
1 2 3 | class RawJsonParser(Parser): def parse(self, method, payload): return payload |
Therefore, we can call the following code for invoking a new parser with JSON returned:
1 2 | from tweepy.parsers import RawJsonParser api = tweepy.API(auth_handler=auth, parser=RawJsonParser()) |
Hi LiangJie — just wanted to thank you for posting this snippet, it saved my day! 😛
Excellent, I was serializng to json again property by property