How to fix the JSONDecodeError: No JSON object can be decrypted: row 1 column 0 (char 0) "?

I am trying to get the Twitter API search results for a given hashtag using Python, but I am having problems with this error "There is no JSON object that can be decoded." I had to add an extra% to the end of the url to prevent a string formatting error. Could this JSON error be related to extra%, or is it caused by something else? Any suggestions would be much appreciated.

Excerpt:

import simplejson import urllib2 def search_twitter(quoted_search_term): url = "http://search.twitter.com/search.json?callback=twitterSearch&q=%%23%s" % quoted_search_term f = urllib2.urlopen(url) json = simplejson.load(f) return json 
+7
json python simplejson twitter
source share
1 answer

There were problems with your source code. At first, you never read the content from Twitter, you just opened the URL. Secondly, in the URL you set a callback (twitterSearch). What the callback does is transferring the returned json to the function call, so in this case it would be twitterSearch (). This is useful if you want a special function to handle returned results.

 import simplejson import urllib2 def search_twitter(quoted_search_term): url = "http://search.twitter.com/search.json?&q=%%23%s" % quoted_search_term f = urllib2.urlopen(url) content = f.read() json = simplejson.loads(content) return json 
+8
source share

All Articles