[Flask] Question on iterating over records read using pyexcel

Jim Icenhower jicenhower at yahoo.com
Sat Oct 10 17:48:53 CEST 2015


I'm getting an error when iterating over the records read from a very simple xlsx file. I've tried reading a csv file and the results are the same. The code below prints the 3 records in the file then it seems like it's attempting to read another record from the records collection. What am I doing wrong?
Thanks!
Here's the code:import os

from models import Product, ProductType, Event, CarClass, Vehicle, Registrant
from flask import render_template
from flask.ext.appbuilder.views import ModelView, BaseView, has_access, expose
from flask.ext.appbuilder.charts.views import ChartView
from flask.ext.appbuilder.models.sqla.interface import SQLAInterface
from flask.ext.appbuilder.widgets import ListBlock, ShowBlockWidget
import pyexcel as pe
from werkzeug import secure_filenamefrom app import dbdef doEventsImport():
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            fullName = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(fullName)

            records = pe.get_records(file_name=fullName)
            for record in records:
                print record
Console ouput of the 3 records:{'EventKey': u'TXABCD2014', 'Name': u'Texas All British Car Days 2014-a'}{'EventKey': u'TXABCD2015', 'Name': u'Texas All British Car Days 2015'}{'EventKey': u'TXABCD2016', 'Name': u'Texas All British Car Days 2016'}
Error stack:
2015-10-10 10:43:31,993:INFO:werkzeug:127.0.0.1 - - [10/Oct/2015 10:43:31] "POST /importEvents HTTP/1.1" 500 -Traceback (most recent call last):  File "C:\Python27\lib\site-packages\flask\app.py", line 1836, in __call__    return self.wsgi_app(environ, start_response)  File "C:\Python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app    response = self.make_response(self.handle_exception(e))  File "C:\Python27\lib\site-packages\flask\app.py", line 1403, in handle_exception    reraise(exc_type, exc_value, tb)  File "C:\Python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app    response = self.full_dispatch_request()  File "C:\Python27\lib\site-packages\flask\app.py", line 1478, in full_dispatch_request    response = self.make_response(rv)  File "C:\Python27\lib\site-packages\flask\app.py", line 1566, in make_response    raise ValueError('View function did not return a response')ValueError: View function did not return a response Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20151010/61b3b2c3/attachment.html>


More information about the Flask mailing list