title: URL encode a non-value pair in Python
body: <p>I'm trying to use Google's AJAX (JSON) Web Search API in Python. I'm stuck because Python's urllib.urlencode() only takes value pairs, not strings by themselves, to encode. In Google's API, the query string is the search term and it doesn't associate with a variable.</p>
  
  <pre><code>query = "string that needs to be encoded"
  params = urllib.urlencode(query) # THIS FAILS
  # http://code.google.com/apis/ajaxsearch/documentation/reference.html
  url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;rsz=large&amp;%s&amp;%s" % (params, GOOGLE_API_KEY)
  
  request = urllib2.Request(url)
  request.add_header('Referer', GOOGLE_REFERER)
  
  search_results = urllib2.urlopen(request)
  raw_results = search_results.read()
  json = simplejson.loads(raw_results)
  estimatedResultCount = json['responseData']['cursor']['estimatedResultCount']
  
  if estimatedResultCount != 0:
      print "Google: %s hits" % estimatedResultCount
  </code></pre>
  
  <p>How do I urlencode my search terms?</p>