Export to GitHub

pybing - issue #9

json loads error


Posted on Feb 17, 2012 by Massive Camel

This is the example: from pybing import Bing bing = Bing('APPID') resp = bing.search_web('python') print resp['SearchResponse']['Web']['Total']

Here is the output : Traceback (most recent call last): File "test1.py", line 4, in <module> resp = bing.search_web('python') File "/home/zz/Desktop/bruteforce/pybing/bing.py", line 48, in search_web return self.search(query, source_type=constants.WEB_SOURCE_TYPE) File "/home/zz/Desktop/bruteforce/pybing/bing.py", line 45, in search return json.loads(contents) File "/usr/lib/python2.7/json/init.py", line 326, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) TypeError: expected string or buffer

I am using python2.7 and the latest pybing

diff --git a/pybing/bing.py b/pybing/bing.py index 3063e6b..4fd68bc 100644 --- a/pybing/bing.py +++ b/pybing/bing.py @@ -40,7 +40,7 @@ class Bing(object):

     query_string = urllib.urlencode(kwargs)
     contents = urllib2.urlopen(constants.JSON_ENDPOINT + '?' + query_string

- return json.loads(contents) + return json.loads(contents.read())

 def search_web(self, query):
     return self.search(query, source_type=constants.WEB_SOURCE_TYPE)

Comment #1

Posted on Feb 23, 2012 by Happy Monkey

I am having this problem as well, but worked around it by using the Query API wrapper (example on homepage)

Comment #2

Posted on Mar 1, 2012 by Helpful Horse

I am also having this issue using 2.6.5.

Comment #3

Posted on Mar 1, 2012 by Massive Bird

Just posted a change according to the diff. Let me know if that fixes it.

Comment #4

Posted on Mar 22, 2012 by Helpful Hippo

@jgeewax, I had the same problem and your change worked, thanks :)

To save any future users some time: -open pybing/bing.py -change return json.loads(contents) to return json.loads(contents.read())

For some reason pulling the trunk didn't include this update... svn checkout http://pybing.googlecode.com/svn/trunk/

Status: Fixed

Labels:
Type-Defect Priority-Medium