title: Python : TypeError: 'NoneType' object has no attribute '__getitem__'
body: <p>When i run my python code through terminal m getting this error :</p>
  
  <pre><code>def GPlag(text,encode=False):
          import urllib, urllib2, json
  
          if encode == True:
              text = text.encode('utf-8')
  
          query = urllib.quote_plus(text)
          base_url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;q='
          url = base_url + '%22' + query + '%22'
          request = urllib2.Request(url,None)
          response = urllib2.urlopen(request)
          result = json.load(response)
          output = []
  
          if result['responseData']['results'] != []:
              firstMatch = result['responseData']['results'][0]
              output.append(firstMatch['title'])
              output.append(firstMatch['visibleUrl'])
              output.append(firstMatch['content'])
  
          return output
  
          def callGPlag(n):
              for s in n:
                  outcome = GPlag(s,encode=True)
  </code></pre>
  
  <p>It gives;</p>
  
  <pre><code>TypeError: 'NoneType' object has no attribute '__getitem__'
  </code></pre>
  
  <p>in this <code>if result['responseData']['results']</code> line. Here is the traceback:</p>
  
  <pre><code>Traceback (most recent call last): 
   ... in &lt;module&gt; GPlagFile(sys.argv[1]) 
   ... in GPlagFile outcome = GPlag(s,encode=True) 
   ... in GPlag if 'results' in result['responseData']: 
  TypeError: argument of type 'NoneType' is not iterable
  </code></pre>