Forums

My application from Github only partially works

I've successfully cloned my project from Github into PA and configured my wsgi file properly -- or at least I assume so because the landing page shows up. For some reason, though, when using the search function, I get an internal server error. I suspect it's something to do with my using whoosh, but I am inexperienced enough that I'm not really sure. Everything works just fine when I run it locally, so I probably have something configured improperly, but I don't even really know where to start looking.

Thanks in advance for your help!

The first place to look is the log files. On the web tab, you'll see three links to them: the important ones are the server log and the error log. If you need any help decoding what's in there, we may be able to help -- just paste the errors into your next post, indented with four spaces.

Ah, thank you so much! Didn't know that I had access to error logs.

Posted too soon -- I initially saw errors for a problem that I'd fixed locally, but thought that the top was most recent. I pulled my most recent changes from github, and now I'm seeing an error that I'm not sure how to address, because it's working properly locally:

2013-10-02 14:14:45,138 :Exception on /search_results/DCY [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/kaburgett/flask-platespotting/spot/views.py", line 31, in search_results

IndexError: list index out of range

And here's my views.py route for that url path:

@plate.route('/search_results/<query>')
def search_results(query):
    plate_type = ''
    flag_image = ''
    plate_type_options = {'D': 'Diplomat', 'C': 'Foreign Consul', 'S': 'Non-diplomatic Staff'}
    plate_type_index = query[0].upper()

    if plate_type_index in plate_type_options:
        plate_type = plate_type_options[plate_type_index]

    country = query[1:3]
    results = Code.query.whoosh_search(country).all()

    if results:
        flag_image = results[0].country.country_name.replace(' ', '-')

    return render_template('country_page.html',
        query = query,
        results = results,
        plate_type = plate_type,
        flag_image = flag_image)

Which line is the error on? That is, which one is line 31? I can see a couple of indexes into lists there, and it could be any of them.

That said, I suspect the problem is that query doesn't hold what you'd expect. One thing that might help debug -- if you print something to stderr, then it will come out in the server log. So, if you add

import sys

to the top of your views.py, and then put

print >> sys.stderr, "Query is %r" % (query,)

...at the start of search_results then it should help clarify things.