Works. But I can't access the data. On Mon, 11 Feb 2019, 21:02 sandeep patel <[email protected] wrote:
> In fact, this is an open issue > <https://github.com/web2py/web2py/issues/2015> for the same problem. You > can check that as well > > On Mon, Feb 11, 2019 at 11:27 PM sandeep patel <[email protected]> > wrote: > >> I had the same issue. I have solved this way. >> Please try this >> You have to changing line 926 of gluon/packages/dal/pydal/objects.py from >> reader = csv.reader(csvfile, delimiter=delimiter, >> quotechar=quotechar, quoting=quoting) >> to >> reader = csv.reader(codecs.iterdecode(csvfile,'utf-8'), >> delimiter=delimiter, >> quotechar=quotechar, quoting=quoting) >> >> After changes done, you have to execute the web2py.py >> >> Thanks >> SP >> >> On Mon, Feb 11, 2019 at 11:04 PM Maurice Waka <[email protected]> >> wrote: >> >>> 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 >>> >>> -- >>> 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. >>> >> -- > 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. > -- 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.

