1 Reply Latest reply on Jul 31, 2013 3:33 PM by Ben Sullins

    TableauException (303): Invalid argument 'value' when using the Tableau Data Extract API in Python

    Ben Sullins

      Greetings,

       

      I am attempting to insert some bit.ly metrics into a tde using the data extract api and python. I'm receiving the error below from this code:

      import sys
      import bitly_api
      import dataextract as tde
      import os
      import datetime
      from datetime import date
      from config import config
      import time
      
      
      #vars
      load_date = date.today()
      print 'load_date=', load_date
      
      # Create tde
      try:
          tdefile = tde.Extract('bitly_clicks.tde')
      except:
          os.remove('bitly_clicks.tde')
          tdefile = tde.Extract('bitly_clicks.tde')
      print 'tde_ok'
      
      # Define TDE
      tableDef = tde.TableDefinition()
      tableDef.addColumn('load_date', tde.Type.CHAR_STRING)
      tableDef.addColumn('click_date', tde.Type.CHAR_STRING)
      ##link attribs
      tableDef.addColumn('archived', tde.Type.CHAR_STRING)
      tableDef.addColumn('user_ts', tde.Type.CHAR_STRING)
      tableDef.addColumn('title', tde.Type.CHAR_STRING)
      tableDef.addColumn('created_at', tde.Type.CHAR_STRING)
      tableDef.addColumn('modified_at', tde.Type.CHAR_STRING)
      tableDef.addColumn('private', tde.Type.CHAR_STRING)
      tableDef.addColumn('aggregate_link', tde.Type.CHAR_STRING)
      tableDef.addColumn('long_url', tde.Type.CHAR_STRING)
      tableDef.addColumn('client_id', tde.Type.CHAR_STRING)
      tableDef.addColumn('link', tde.Type.CHAR_STRING)
      tableDef.addColumn('clicks', tde.Type.DOUBLE)
      
      # Create table
      table = tdefile.addTable('Extract', tableDef)
      newrow = tde.Row(tableDef)
      
      #connect to bitly
      conn_btly = bitly_api.Connection(access_token=config['ACCESS_TOKEN'])
      
      #get links
      links = conn_btly.user_link_history()
      
      print 'got links!'
      
      #links loop
      for link in links:
          
          #get clicks
          #clicks = conn_btly.link_clicks(link_full)
          clicks = conn_btly.link_clicks(link['link'], rollup=False, unit="day")
      
          print 'got clicks for ', link['link']
          
          #clicks loop
          for click in clicks:
      
                  #convert to redable time
                  click['click_date'] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(click['dt']))
      
                  newrow.setCharString(0, load_date.strftime('%m/%d/%Y')) #load_date
                  newrow.setCharString(1, click['click_date']) #click_date
                  newrow.setCharString(2, link['archived']) #archived
                  newrow.setCharString(3, link['user_ts']) #user_ts
                  newrow.setCharString(4, link['title']) #title
                  newrow.setCharString(5, link['created_at']) #created_at
                  newrow.setCharString(6, link['modified_at']) #modified_at
                  newrow.setCharString(7, link['private']) #private
                  newrow.setCharString(8, link['aggregate_link']) #aggregate_link
                  newrow.setCharString(9, link['long_url']) #long_url
                  newrow.setCharString(10, link['client_id']) #client_id
                  newrow.setCharString(11, link['link']) #link
                  newrow.setDouble(12, click['clicks']) #clicks
                  table.insert(newrow)
                  
      #close the file
      tdefile.close()
      

       

       

      Error

       

      Traceback (most recent call last):
        File "C:\python-tde\bitly_clicks.py", line 70, in <module>
          newrow.setCharString(2, link['archived']) #archived
        File "C:\Python27\lib\site-packages\dataextract\Base.py", line 294, in setCharString
          raise Exceptions.TableauException(result, wstring_at(tablib.TabGetLastErrorMessage()))
      TableauException: TableauException (303): Invalid argument 'value'
      

       

      Thoughts?

       

      cc: Tamas Foldi, Russell Christopher, Andy Cotgreave