If you move that code to a server-side it works…
On the client side: I think the problem in this is using the URLMedia - in the docs and in the auto-complete it comes with a warning:
Create a Media object representing the data at a specific URL. Caution: Getting data from URLs directly in your code will often fail for security reasons, or fail to handle binary data.
I think this is the issue that you faced… I wouldn’t use an asset here - I would use the data_table media object…
Using the media object in the datatable worked fine on the client (if you make your tables client readable/writable):
file_contents = app_tables.files.get(filetype='MARSYS')['file'].get_bytes()
csv_string = file_contents.decode()
But I would definitely put this kind of function on the server - it will be quicker and more secure.
@anvil.server.callable
def load_MARSYS():
file_contents = app_tables.files.get(filetype='MARSYS')['file'].get_bytes()
csv_string = file_contents.decode()
line_list = csv_string.split('\n')
for line in line_list:
flist = line.split(',')
d = {
'industry': 'Maritime',
'top_level': 'Fleet',
'category': flist[2],
'sub_category': flist[3],
'vendor': flist[4],
'int_serial': flist[5],
'int_eth': flist[6],
'int_usb': flist[7],
'modbus': flist[8],
'tech_vendor': flist[9],
'tech_product': flist[10],
'tech_version': flist[11],
'notes': flist[12],
'marsys_key': flist[14],
'tech_key': flist[15],
}
app_tables.marsys.add_row(**d)
Edit: Answer above probably superseded by this thread:
Please post the most simple example loading a .csv into a table - #14 by stucork