[Flask] Question on iterating over records read using pyexcel

Jonathan Chen tamasiaina at gmail.com
Sat Oct 10 19:01:18 CEST 2015


No worries, I run into that one often by accident, so I'm use to seeing
that error.


~Jonathan C.

On Sat, Oct 10, 2015 at 9:04 AM, Jim Icenhower <jicenhower at yahoo.com> wrote:

> What a newbie mistake! Thanks for the help.
>
> Jim
>
> ------------------------------
> *From:* Jonathan Chen <tamasiaina at gmail.com>
> *To:* Jim Icenhower <jicenhower at yahoo.com>
> *Cc:* "flask at python.org" <flask at python.org>
> *Sent:* Saturday, October 10, 2015 10:58 AM
> *Subject:* Re: [Flask] Question on iterating over records read using
> pyexcel
>
> Yeah, the issue is that you are not returning anything. If you just do a
> return record it should not throw an error.
>
>
> ~Jonathan C.
>
> On Sat, Oct 10, 2015 at 8:48 AM, Jim Icenhower via Flask <flask at python.org
> > wrote:
>
>
>
> 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_filename
>
> from app import db
>
> def 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
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20151010/0994a455/attachment.html>


More information about the Flask mailing list