title: TypeError: 'NoneType' object has no attribute '__getitem__' in python
body: <p>I am using a code for fetching no. of hits of a particular phrase for implementing Semantic Orientation.</p>
  
  <pre><code>def hits(word1,word2=""):
  query = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;q=%s"
  if word2 == "":
      results = urllib.urlopen(query % word1)
  else:
      results = urllib.urlopen(query % word1+" "+"AROUND(10)"+" "+word2)
  json_res = json.loads(results.read())
  google_hits=int(json_res['responseData']['cursor']['estimatedResultCount'])
  return google_hits
  </code></pre>
  
  <p>but when I am giving a long file containing phrases it executes upto some extent but return Error </p>
  
  <pre><code>"TypeError: 'NoneType' object has no attribute '__getitem__' "
  </code></pre>
  
  <p>the error is dynamic as it sometimes executes some phrases and sometimes not. I think its a problem of google API which I am using.  This function calculates SO using above .</p>
  
  <pre><code>def so(phrase):
  num = hits(phrase,"excellent")
  print num
  den = hits(phrase,"poor")
  print den
  ratio = (num/ den+0.01)*0.6403669724770642
  print ratio
  sop = log(ratio)
  return sop
  </code></pre>
  
  <p>Anyone has idea please help !!!</p>