seladb / github-traffic-stats

A small Python project to pull and store traffic stats for GitHub projects using GitHub API
MIT License
28 stars 13 forks source link

TypeError: expected string or buffer while running collect #3

Closed dapper-hacker closed 4 years ago

dapper-hacker commented 4 years ago

Hi, I am trying to run the code with python 2.7 on my mac. When I am running the script, I get this error.

Vinayaks-MacBook-Pro:github-traffic-stats$ python github_traffic_stats.py -t xxxxxxxxxxxxxxxxxxxxxx -o IBM -r db2-samples -c collect Traceback (most recent call last): File "github_traffic_stats.py", line 102, in main() File "github_traffic_stats.py", line 99, in main collect(db=db, user=args.github_user, passwd=args.github_password, token=args.github_access_token, repo=a rgs.github_repo, org=args.github_org) File "github_traffic_stats.py", line 39, in collect db_data = json.loads(db.get(timestamp)) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/init.py", line 339, i n loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) TypeError: expected string or buffer

Based on my evaluation, I can fetch the data for traffic and print it properly until it goes into this code snippet for loading it into pickledb:

db_data = json.loads(db.get(timestamp))
if db_data['uniques'] < data['uniques']:
db.set(timestamp, json.dumps(data))
found_new_data = True'''

Perhaps the github json response has changed?

dapper-hacker commented 4 years ago

RESOLVED: I had to change line 32 if db.get(timestamp) is None: to if db.get(timestamp) is False:

I think it was never inserting any data while running the script for the first time and directly going into the else condition which invoked db_data = json.loads(db.get(timestamp))

But there was no value in the db.

seladb commented 4 years ago

Thanks for looking into this!

Will you consider creating a PR with the fix?

btw, I'd go with something like if db.get(timestamp) is None or db.get(timestamp) is False to cover both options

dapper-hacker commented 4 years ago

Good Suggestion, will add it. Will create the pull request.

seladb commented 4 years ago

I've just upgraded github-traffic-stats to Python 3 and fixed this issue also.