Maybe you should encode your bing url.

Richard

On Thu, Jul 5, 2012 at 4:05 PM, adohertyd <adoher...@hotmail.com> wrote:

> I am trying to get a json response from 2 URL's and showing in on a
> results page. I'm getting an error saying that the page I'm redirecting to
> in order to show the json data is not defined but this only happens with
> one of the url's being contacted. I'm probably not being very clear with
> this so I will show you some code:
>
>
> import urllib2
>
> def index():
>     form = FORM(''...
>     if form.process().accepted:
>         session.term=request.vars.query
>         redirect(URL('results'))
>     elif form.errors: ...
>     return dict(form=form)
>
> def __process():
>     term = session.term
>     term = urllib2.quote("'" + term + "'")
>     return dict(term=term)
>
> def results():
>     import requests
>
>     blekko = "http://www.blekko.com/?q=%(term)s+/json&auth=<mykey>" %__process
> ()
>     blekkoresults = urllib2.urlopen(blekko).read()
>
>     bing = "
> https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%(term)s&$top=50&$format=json
> "
>     API_KEY = 'mykey'
>     r = requests.get(bing % __process(), auth=('', API_KEY))
>     bingresults = r.json
>
>    return blekkoresults, bingresults
>
> The line 'bing= ' is causing the issue. If I comment out the bing section
> of the code, the blekko part returns no problem. However, with the bing
> section included I get the following error:
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
>
> Traceback (most recent call last):
>   File "C:\web2py\gluon\restricted.py", line 205, in restricted
>     exec ccode in environment
>   File "C:\web2py\applications\metasearch2\views\manage/results.html", line 
> 86, in <module>
> NameError: name 'results' is not defined
>
> Can anyone please tell me what's going on? If I run this program in IDLE
> it returns the bing results so it is definitely a web2py issue.
>

Reply via email to