Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: invalid literal for int() with base 10: 'Second' #1369

Closed
apparao84 opened this issue Apr 17, 2024 · 3 comments
Closed

ValueError: invalid literal for int() with base 10: 'Second' #1369

apparao84 opened this issue Apr 17, 2024 · 3 comments

Comments

@apparao84
Copy link

apparao84 commented Apr 17, 2024

Describe the bug
When calling the IncrementalExtract refresh bridge refresh script as mentioned below We are getting below error. This worked successfully until last week.

Error:- ValueError: invalid literal for int() with base 10: 'Second'

Versions
Details of your environment, including:
Tableau Online
Python version: 3.8
TSC library version 3.22

To Reproduce
Steps to reproduce the behavior. Please include a code snippet where possible.

# Name of the data source in tableau
datasource = sys.argv[1]
 
tableau_auth = tsc.PersonalAccessTokenAuth(
    token_name=personal_access_token_name,
    personal_access_token=personal_access_token_secret,
    site_id=site
)
server = tsc.Server(tableau_server, use_server_version=True)
server.auth.sign_in(tableau_auth)
 
# Get datasource id from datasource name
req_option = tsc.RequestOptions(pagesize=1000)
req_option.filter.update([tsc.Filter(tsc.RequestOptions.Field.Name, tsc.RequestOptions.Operator.Equals, datasource)])
all_datasources = list(tsc.Pager(server.datasources, req_option))
 
datasource_id = all_datasources[0].id
 
# Get 1000 tasks and then filter for only extract tasks under the datasource id of interest
# I don't believe you can filter tasks
all_extracts = list(tsc.Pager(server.tasks, tsc.RequestOptions(pagesize=1000)))
 
# The task type for incremental extracts is 'IncrementExtractTask' and full extracts is 'extractRefresh'
# The task type for incremental exrracts via Bridges is 'IncrementExtractViaBridgeTask'
extracts = [i for i in all_extracts if (i.target is not None and i.target.id == datasource_id) and ('IncrementExtractViaBridgeTask' == i.task_type)]
 
incremental_extract_obj = extracts[0]
 
# Trigger the incremental extract associated with the datasource
update_xml = server.tasks.run(incremental_extract_obj)
job_id = xmltodict.parse(update_xml)['tsResponse']['job']['@id']
print(f"Refresh extract job {job_id} created")

Results
What are the results or error messages received?

C:\>D:\Python\python.exe C:\TableauPythonScripts\TableauExtractIncRefTrigScript.py Datasource_name
==================
Traceback (most recent call last):
  File "D:\Python\lib\site-packages\tableauserverclient\models\interval_item.py", line 183, in interval
    if not (1 <= int(interval_value) <= 31):
ValueError: invalid literal for int() with base 10: 'Second'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\TableauPythonScripts\TableauExtractIncRefTrigScript.py", line 31, in <module>
    all_extracts = list(tsc.Pager(server.tasks, tsc.RequestOptions(pagesize=1000)))
  File "D:\Python\lib\site-packages\tableauserverclient\server\pager.py", line 40, in __iter__
    current_item_list, last_pagination_item = self._endpoint(self._options)
  File "D:\Python\lib\site-packages\tableauserverclient\server\endpoint\endpoint.py", line 190, in wrapper
    return func(self, *args, **kwargs)
  File "D:\Python\lib\site-packages\tableauserverclient\server\endpoint\tasks_endpoint.py", line 36, in get
    all_tasks = TaskItem.from_response(server_response.content, self.parent_srv.namespace, task_type)
  File "D:\Python\lib\site-packages\tableauserverclient\models\task_item.py", line 53, in from_response
    return list(all_tasks)
  File "D:\Python\lib\site-packages\tableauserverclient\models\task_item.py", line 51, in <genexpr>
    all_tasks = (TaskItem._parse_element(x, ns) for x in all_tasks_xml)
  File "D:\Python\lib\site-packages\tableauserverclient\models\task_item.py", line 64, in _parse_element
    schedule_item_list = ScheduleItem.from_element(element, ns)
  File "D:\Python\lib\site-packages\tableauserverclient\models\schedule_item.py", line 223, in from_element
    ) = cls._parse_element(schedule_xml, ns)
  File "D:\Python\lib\site-packages\tableauserverclient\models\schedule_item.py", line 298, in _parse_element
    interval_item = ScheduleItem._parse_interval_item(frequency_detail_elem, frequency, ns)
  File "D:\Python\lib\site-packages\tableauserverclient\models\schedule_item.py", line 276, in _parse_interval_item
    return MonthlyInterval(start_time, interval_value)
  File "D:\Python\lib\site-packages\tableauserverclient\models\interval_item.py", line 151, in __init__
    self.interval = str(interval_value)
  File "D:\Python\lib\site-packages\tableauserverclient\models\interval_item.py", line 187, in interval
    raise ValueError(error)
ValueError: Invalid interval value for a monthly frequency: Second.
@jorwoods
Copy link
Contributor

@apparao84 If you wrap your code in triple backticks, it will format it as code.

print("formatted as code!")

@apparao84
Copy link
Author

apparao84 commented Apr 19, 2024

@jorwoods We are not even able to retrieve/get any data from server.tasks library. Seems it is an issue with server.tasks library itself. If we run the same code for different library server.jobs or server.datasources we are able to print the data. We had this script running successfully for more than a year now and since last week it is not completing successfully.

We are running below same script provided in Tableau Server client API reference guide to print the data from server.tasks and getting below error.

Example code (Reference to code : https://tableau.github.io/server-client-python/docs/api-ref#tasks)

import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
server = TSC.Server('https://SERVERURL')

with server.auth.sign_in(tableau_auth):
    all_tasks, pagination_item = server.tasks.get()
    print("\nThere are {} tasks on site: ".format(pagination_item.total_available))
    print([task.id for task in all_tasks])

Error we are getting:

C:\Python>python.exe C:\Refresh-Scripts\TableauExtractIncxxxx.py
Traceback (most recent call last):
  File "C:\Python\Lib\site-packages\tableauserverclient\models\interval_item.py", line 181, in interval
    if not (1 <= int(interval_value) <= 31):
                 ^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'Second'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Refresh-Scripts\ableauExtractIncxxxx.py", line 23, in <module>
    all_tasks, pagination_item = server.tasks.get()
                    ^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\server\endpoint\endpoint.py", line 205, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\server\endpoint\tasks_endpoint.py", line 37, in get
    all_tasks = TaskItem.from_response(server_response.content, self.parent_srv.namespace, task_type)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\models\task_item.py", line 53, in from_response
    return list(all_tasks)
           ^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\models\task_item.py", line 51, in <genexpr>
    all_tasks = (TaskItem._parse_element(x, ns) for x in all_tasks_xml)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\models\task_item.py", line 64, in _parse_element
    schedule_item_list = ScheduleItem.from_element(element, ns)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\models\schedule_item.py", line 223, in from_element
    ) = cls._parse_element(schedule_xml, ns)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\models\schedule_item.py", line 298, in _parse_element
    interval_item = ScheduleItem._parse_interval_item(frequency_detail_elem, frequency, ns)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\models\schedule_item.py", line 276, in _parse_interval_item
    return MonthlyInterval(start_time, interval_value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\models\interval_item.py", line 149, in __init__
    self.interval = str(interval_value)
    ^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\tableauserverclient\models\interval_item.py", line 185, in interval
    raise ValueError(error)
ValueError: Invalid interval value for a monthly frequency: Second.

C:\Python>

@bcantoni
Copy link
Contributor

bcantoni commented May 4, 2024

I realized we have an existing bug open to deal with these interval types, so I'll close this issue in favor of the existing #1358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants