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

Below error being produced on using querying.get_subscriptions_dataframe(conn) #85

Open
agrasurbhi opened this issue Jun 7, 2022 · 3 comments

Comments

@agrasurbhi
Copy link


KeyError Traceback (most recent call last)
/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3079 try:
-> 3080 return self._engine.get_loc(casted_key)
3081 except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'content'

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last)
/opt/anaconda3/lib/python3.8/site-packages/tableau_api_lib/utils/common.py in flatten_dict_column(df, keys, col_name, add_col_prefix)
20 if add_col_prefix is True:
---> 21 df[col_name + "_" + key] = df[col_name].apply(lambda col: col[key])
22 elif add_col_prefix is False:

/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py in getitem(self, key)
3023 return self._getitem_multilevel(key)
-> 3024 indexer = self.columns.get_loc(key)
3025 if is_integer(indexer):

/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3081 except KeyError as err:
-> 3082 raise KeyError(key) from err
3083

KeyError: 'content'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
in
3 for i in range(len(all_sites)):
4 #conn.switch_site(all_sites.loc[i,'contentUrl']) # Here we are switching to each site
----> 5 all_user=querying.get_subscriptions_dataframe(conn)
6

/opt/anaconda3/lib/python3.8/site-packages/tableau_api_lib/utils/querying/subscriptions.py in get_subscriptions_dataframe(conn)
17 def get_subscriptions_dataframe(conn):
18 subscriptions_df = pd.DataFrame(get_all_subscription_fields(conn))
---> 19 subscriptions_df = flatten_dict_column(subscriptions_df, keys=['id', 'type'], col_name='content')
20 subscriptions_df = flatten_dict_column(subscriptions_df, keys=['id', 'name'], col_name='schedule')
21 subscriptions_df = flatten_dict_column(subscriptions_df, keys=['id', 'name'], col_name='user')

/opt/anaconda3/lib/python3.8/site-packages/tableau_api_lib/utils/common.py in flatten_dict_column(df, keys, col_name, add_col_prefix)
28 except KeyError:
29 # TODO(elliott): change the col_name reference below be the key name when the key is what's missing
---> 30 raise KeyError(f"No column named '{col_name}' was found in the DataFrame provided.")
31
32

KeyError: "No column named 'content' was found in the DataFrame provided."

@divinorum-webb
Copy link
Owner

Hey @agrasurbhi try this: run pip install -U tableau-api-lib to get the most recent version of the library. Re-run your code, and now if the resulting dataframe does not have the content column then you will receive an empty dataframe rather than getting this error.

I also recommend running this to determine if there is some other issue at play:

response = conn.query_subscriptions()
print(response.content)

If you are seeing some sort of error when querying your subscriptions then please post it to this thread and I'll try to help.

This query_subscriptions method hits the actual REST API endpoint "Query Subscriptions" and this is in turn used by the querying.get_subscriptions_dataframe function. If you have any trouble querying the subscriptions via the actual endpoint, then this explains why the querying function is not working for you.

@divinorum-webb
Copy link
Owner

divinorum-webb commented Jul 7, 2022

For context, here is what I'm seeing when using the querying.get_subscriptions_dataframe function and the query_subscriptions endpoint:
image

@divinorum-webb
Copy link
Owner

@agrasurbhi following up, was your issue resolved by the recommendations above?

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

No branches or pull requests

2 participants