Skip to main content

Hi,

 

Am using Tableau Data API with P Python and creating a .tde. It has worked well apart from when I try to rerun the Python and I get the following error:

 

Traceback (most recent call last):

File "//psf/Home/Desktop/Google Sreadsheet2", line 30, in <module>

   table = tdefile.addTable('Extract',tableDef)

File "C:\Python27\lib\site-packages\dataextract\Base.py", line 484, in addTable

   raise Exceptions.TableauException(result, wstring_at(tablib.TabGetLastErrorMessage()))

TableauException: TableauException (303): duplicate table name”

 

'Extract' is the duplicate table name, but by default has to be the table name, so when you are doing an automatic refresh you get the error? Anyway out of this, or a better method of getting random APIs

 

Code below

 

Thanks in aADvance:

 

import os, datetime

import dataextract as tde

import gspread

import schedule

import time

 

#Step 1: Create the extract file

try:

    tdefile = tde.Extract('GG11.tde')

except:

    os.remove('GG11.tde')

    os.remove('DataExtract.log')

    tdefile = tde.Extract('GG11.tde')

 

#Step 2: Connect to the Google Spreadsheet and put the data in a list of lists

gsclient = gspread.login(

spreadsheet = gsclient.open_by_key('0')

worksheet = spreadsheet.get_worksheet(0)

data = worksheet.get_all_values()

 

#Step 3: Create the tableDef and the table

try:

    tableDef = tde.TableDefinition()

except:

    os.remove()

    tableDef = tde.TableDefinition()

   

tableDef.addColumn('number', tde.Type.CHAR_STRING)

try:

    table = tdefile.addTable('Extract',tableDef)

 

#Step 4: Loop through our list of lists of data,

#   put it into rows, and insert the rows

newrow = tde.Row(tableDef)

for row in data[10:]:

    newrow.setCharString(0,row[2])

table.insert(newrow)

 

#Step 5: Close the tde

tdefile.close()

3 answers
  1. Mar 5, 2014, 11:55 PM

    Hi Ranjit,

     

    I have been getting this duplicate table name error too.

     

    My solution:

    Check for and delete the existing extract BEFORE using the dataextract.Extract() method.

     

    So my original code was this:

    ###########⌗BAD############

    # ⌗create the extract

    # try:

    #     ⌗try to create the extract file

    #     tdefile = tde.Extract(dataFolder+'DataExtract.tde')

    # except:

    #     ⌗if the file already exists, delete it

    #     os.remove(dataFolder+'DataExtract.tde')

    #     ⌗create the file now

    #     tdefile = tde.Extract(dataFolder+'DataExtract.tde')

     

    My new, working code does this:

    ###########⌗GOOD############

    ⌗if the extract already exists, delete it.

    if os.path.isfile(dataFolder+'DataExtract.tde'):

      os.remove(dataFolder+'DataExtract.tde')

    ⌗now create a new one

    tdefile = tde.Extract(dataFolder+'DataExtract.tde')

     

    Hopefully this helps!

0/9000