I had a similar issue.
I solve it doing this:
f = request.vars.csvfile.file
import io
file = io.TextIOWrapper(f, encoding='utf-8')
El lunes, 11 de febrero de 2019, 14:34:18 (UTC-3), Maurice Waka escribió:
>
> I shifted to web2py/python3. In python2.7 I was able to upload csv files
> but using the same code below I get an error.
> For example:
> def import_csv():
> form = FORM(INPUT(_type = 'file', _name = 'csv_file'),
> INPUT(_type = 'submit', _value = T('Import')))
> return dict(form=form)
> @mobilize
> @auth.requires_login()
> def index1():
> if request.vars.csvfile != None:
> # set values
> table = db[request.vars.table]
> file = request.vars.csvfile.file
> # import csv file
> table.import_from_csv_file(file)
> # update who imported
> query = db.food_data.protein==""
> db(query).update(protein="")
> response.flash = 'Data uploaded'
> return dict()
>
> The error is this
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
>
> Traceback (most recent call last):
> File "/home/mauricewaka/web2py/gluon/restricted.py", line 219, in restricted
> exec(ccode, environment)
> File
> "/home/mauricewaka/web2py/applications/Hestque_Wellness/controllers/default.py"
>
> <http://127.0.0.1:8000/admin/default/edit/Hestque_Wellness/controllers/default.py>,
> line 479, in <module>
> File "/home/mauricewaka/web2py/gluon/globals.py", line 421, in <lambda>
> self._caller = lambda f: f()
> File "/home/mauricewaka/web2py/gluon/contrib/user_agent_parser.py", line
> 695, in __call__
> return self.func()
> File "/home/mauricewaka/web2py/gluon/tools.py", line 3867, in f
> return action(*a, **b)
> File
> "/home/mauricewaka/web2py/applications/Hestque_Wellness/controllers/default.py"
>
> <http://127.0.0.1:8000/admin/default/edit/Hestque_Wellness/controllers/default.py>,
> line 329, in index1
> table.import_from_csv_file(file)
> File "/home/mauricewaka/web2py/gluon/packages/dal/pydal/objects.py", line
> 980, in import_from_csv_file
> for lineno, line in enumerate(reader):
> _csv.Error: iterator should return strings, not bytes (did you open the file
> in text mode?)
>
> How can I solve this
>
>
--
CONFIDENCIALIDAD La información
contenida en este mensaje y/o en los
archivos adjuntos es de carácter
confidencial o privilegiada y está
destinada al uso exclusivo del emisor y/o de
la persona o entidad a quien
va dirigida. Si usted no es el destinatario,
cualquier almacenamiento,
divulgación, distribución o copia de esta información
está estrictamente
prohibido y sancionado por la ley. Si recibió este mensaje
por error, por
favor infórmenos inmediatamente respondiendo este mismo mensaje
y borre
éste y todos los archivos adjuntos. Gracias.
CONFIDENTIAL NOTE The
information transmitted in this message and/or
attachments is confidential
and/or privileged and is intented only for use of
the person or entity to
whom it is addressed. If you are not the intended
recipient, any retention,
dissemination, distribution or copy of this
information is strictly
prohibited and sanctioned by law. If you received this
messagge in error,
please reply us this same message and delete this message
and all
attachments. Thank you.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.