python - Py-StackExchange raise a valueError -
i try use stackexchange api , found py-stackexchange library python. installed through easy_install in windows.
here code:
from stackexchange import site, stackoverflow = site(stackoverflow) my_favourite_guy = so.user(2309097) print my_favourite_guy.reputation.format() print len(my_favourite_guy.answers), 'answers'
and here error:
traceback (most recent call last): file "c:\users\tasos\desktop\test - copy.py", line 8, in <module> my_favourite_guy = so.user(2309097) file "build\bdist.win-amd64\egg\stackexchange\__init__.py", line 626, in user u, = self.users((nid,), **kw) file "build\bdist.win-amd64\egg\stackexchange\__init__.py", line 631, in users return self._get(user, ids, 'users', kw) file "build\bdist.win-amd64\egg\stackexchange\__init__.py", line 621, in _get return self.build(root, typ, coll, kw) file "build\bdist.win-amd64\egg\stackexchange\__init__.py", line 598, in build json = self._request(url, kw) file "build\bdist.win-amd64\egg\stackexchange\__init__.py", line 570, in _request json, info = request_mgr.json_request(url, new_params) file "build\bdist.win-amd64\egg\stackexchange\web.py", line 120, in json_request return (json.loads(req.data), req.info) file "c:\python27\lib\json\__init__.py", line 338, in loads return _default_decoder.decode(s) file "c:\python27\lib\json\decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) file "c:\python27\lib\json\decoder.py", line 383, in raw_decode raise valueerror("no json object decoded") valueerror: no json object decoded
i saw in wiki following don't use proxy , code version latest through easy_install:
this result of proxy/router mangling request headers. router/proxy adds headers requesting gzip data, doesn't decompress it, , running old version of code not deal gzip compression. in case, update latest version of library.
the version on pypi out of date (released 2011) , still uses api version 1.1, has been shut down.
the github codebase has been updated use api v2.2, install directly:
pip install git+https://github.com/lucjon/py-stackexchange
or using easy_install
, download current master zip:
easy_install https://github.com/lucjon/py-stackexchange/archive/640eac1525baaf57474ddbc3be2b580f00e4f1e8.zip
to answers listed need call .fetch()
:
print len(my_favourite_guy.answers.fetch()), 'answers'
this fetches first page of answers:
>>> stackexchange import site, stackoverflow >>> = site(stackoverflow) >>> my_favourite_guy = so.user(2309097) >>> print my_favourite_guy.reputation.format() 563 >>> print len(my_favourite_guy.answers.fetch()), 'answers' 19 answers >>> my_favourite_guy = so.user(100297) >>> print my_favourite_guy.reputation.format() 251.2k >>> print len(my_favourite_guy.answers.fetch()), 'answers' 30 answers
i have few more 30 answers, last time checked. use .extend_next()
calls fetch next query set, until run out.
Comments
Post a Comment