Me again! I don't know why I am getting this error. The process() function
takes in a value session.term, processes it, and returns it as a dict type
so that it can be mapped to URL's in the next function. The results()
function sends the variable 'term' to 3 different API URL's which all
should return some json results. The entireweb and blekko results come back
fine if I leave out the bing call; however, the bing results cause the
error 'Dict object has no attribute rstrip'. The problem has to be in the
way I'm calling the Bing API. Would really appreciate some guidance here.
Thanks! This is my default.py controller
def index():
form = FORM('',
INPUT(_name='query', requires=IS_NOT_EMPTY()),
INPUT(_type='submit'))
if form.process().accepted:
session.term=request.vars.query
redirect(URL('results'))
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill the form'
return dict(form=form)
def __process():
import urllib
term=session.term
#do some processing on term
return dict(term=term)
def results():
import urllib
import requests #This is an external library in the site-packages folder
blekko = "http://www.blekko.com/?q=%(term)s+/json&auth=f4c8acf3" %__process
()
blekkoresults = urllib.urlopen(blekko).read()
entireweb =
"http://www.entireweb.com/xmlquery?pz=<mykey>&ip=<myIP>&n=10&of=0&format=json&q=%(term)s"
%__process()
entresults = urllib.urlopen(entireweb).read()
URL =
"https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%(term)s&$top=50&$format=json"
API_KEY= 'mykey'
term = __process()
r = requests.get(URL % {'term': urllib.quote(term)}, auth=('', API_KEY))
bingresults = r.json['d']['results']
return blekkoresults, entresults, bingresults