Anvil uplink configuration

Hello, i am trying to use uplink because i need to import a csv file to a table, so i am testing my uplink with the key and this generic code, after i installed uplink in my machine with the command:

pip install anvil-uplink

And i use this code:

import anvil.server

anvil.server.connect("<uplink key>")

@anvil.server.callable
def say_hello(name):
  print("Hello from the uplink, %s!" % name)

anvil.server.wait_forever()

when i run this on visual studio i get this output:

Connecting to wss://anvil.works/uplink
Anvil websocket open
Connected to "Default environment (published)" as SERVER

Shouldnt i get the print hello output instead? I am not sure how to connect this to my anvil app, so i can use my code to import a csv to my table…

Hi @tiago.mendes

In publishing your uplink key, you have allowed anyone to have unrestricted access to your app and its data tables. I suggest you reset that key quickly.

As for your question, everything looks like it’s working properly. You need to call your say_hello function from within your anvil app in order to see the message printed.

3 Likes

@owen.campbell
Thank you for the fast answer.
Yes i changed my uplink key right away.
Since i am new i didnt know about that, i will try to work now with the csv uploading code.
Thank you!

A few months ago I wrote a quick and dirty upload some csv data example here:

Also above in the same thread there is an example by @alcampopiano using pandas on your local pc

@ianb Thank you so much for sharing your code! it helped a lot!
Now i am getting an error due to csv index i guess.

IndexError: list index out of range at [ServerModule1, line 23](javascript:void(0))

At this line:

app_tables.valoresm2_monthly_table.add_row(Cidade=csv_row[0], Month=csv_row[1], Ano=csv_row[2], Construcao=csv_row[3], Valor=csv_row[4])

Is this related to the csv or to my table composition?

I would look in the CSV first, but you could do:

if len(csv_row) >= 5:
  #app_tables.valoresm2_monthly_table.add_row(Cidade=csv_row[0], Month=csv_row[1], Ano=csv_row[2], Construcao=csv_row[3], Valor=csv_row[4])
  pass
else: 
  print(csv_row)

and see if what prints out to the output is actual malformed data, or if it is just some junk in the csv file like a header row, or a blank line, or missing data etc.

if whatever it prints out does not look important, uncomment the #app_tables… line and you should be able to insert the data skipping the non relevant lines (if they are not relevant)

1 Like

@tiago.mendes

On another note, there is no unique constraint available in the data tables (that I could tell) for any columns, if you ran your code once, you may already have partial data in the data table. If you check the table and would like to load the data from scratch but you don’t want to go through making the table again, you can use the truncate function to clear the table of all data but keep its structure.

In the data table it is the icon that looks like a trash can (er ‘rubbish bin’ )

Loading the same data twice will create duplicate records, using that simple csv method.