Narrowed down to the xml(). Can you help? On Mon, Feb 11, 2019 at 10:04 PM sandeep patel <patelsandeep...@gmail.com> wrote:
> @Lovedie > Can you explain a little bit more? What you mean by can't access the data? > > If you getting the error to import data from CSV. You can try this as well. > > form = FORM(DIV(LABEL('File > input',_for='exampleInputFile'),INPUT(_type='file',_name='csvsheet',_id="exampleInputFile"),_class='from-group'),BUTTON('Submit',_type='submit',_class="btn > btn-primary")) > if form.process().accepted: > try: > for i in > csv.DictReader(codecs.iterdecode(request.vars.csvsheet.file,'utf-8')): > db['table name'].insert(**i) > except Exception as e: > print(e) > form.errors.csvfile = 'Invalid file format.' > > Thanks > SP > > On Mon, Feb 11, 2019 at 11:45 PM Lovedie JC <lbjc1...@gmail.com> wrote: > >> Works. >> But I can't access the data. >> >> On Mon, 11 Feb 2019, 21:02 sandeep patel <patelsandeep...@gmail.com >> 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 < >>> patelsandeep...@gmail.com> 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 <mauricew...@gmail.com> >>>> 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 web2py+unsubscr...@googlegroups.com. >>>>> 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 web2py+unsubscr...@googlegroups.com. >>> 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 web2py+unsubscr...@googlegroups.com. >> 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 a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/t2SEQC9o-ic/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.