0

I'm using Django for a per project. When I use an external API call in my views (function based view), I'm getting bad responses.

Here are my code snippits:

views.py

def stock_name(request):
    if request.method == 'POST':
        form = StockForm(request.POST)
        if form.is_valid():
            stock_ticker = form.cleaned_data["stock_ticker"]
            return render(request, 'article/stockinfo.html', get_search_query(stock_ticker),context_instance=RequestContext(request))
    else:
        form = StockForm

    return render(request, 'article/index.html', {"form" : form })

.

def get_search_query(stock_ticker):
    print stock_ticker
    api = articleAPI('e4534187a7915ba69b41c1beab029d0f:8:71762357')
    articles = api.search(q = stock_ticker,
                          fq = {"news_desk" : "technology"},
                          fl = ["headline", "abstract", "pub_date", "news_desk", "_id"],
                          sort = "newest",
                          begin_date = str(20100101),
                          end_date = str(20150401),
                          )
    print articles

    return articles

It seems I'm getting some kind of bad response and it looks like a wsgi error. But If run the get_serach_query as a standalone code, it works. The get_search_query takes a stock ticker and retrieves results with New York Times Article API.

Saagar Elias Jacky
  • 2,684
  • 2
  • 14
  • 28
ablimit
  • 2,301
  • 6
  • 27
  • 41

0 Answers0