Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
olaoyesunday1
Contributor III
Contributor III

Generate a python script that read data from Qlik Cloud and Convert it to PDF

Hello folks,

 I am trying to use python scripts to read data from a Qlik Cloud bar chart, output it as a pdf file, but I keep on getting this  error bellow :

    Failed to fetch chart data. Status code: 401
Traceback (most recent call last):
File "c:\Users\Sunday\Documents\ClikModules\app3v2.py", line 39, in <module>
plt.bar(df['Manager'], df['Sales'])
~~^^^^^^^^^^^
File "C:\Users\Sunday\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\frame.py", line 3893, in __getitem__
indexer = self.columns.get_loc(key)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Sunday\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\indexes\range.py", line 418, in get_loc
raise KeyError(key)
KeyError: 'Manager'

here is my scripts to help me to check what I did wrong: 

import requests
import pandas as pd
import matplotlib.pyplot as plt
import base64

# Qlik Sense Configuration
qlik_app_id = "f7ff978a-0e41-4e4c-86e5-59ffd77bb218"
qlik_chart_object_id = "XgePP"

# Authentication credentials (replace with your actual credentials)
qlik_username = "sunday.olaoye@example.com"
qlik_password = "password"

# Fetch data from Qlik Sense with authentication headers
qlik_data_url = f"{qlik_base_url}/api/v1/apps/{qlik_app_id}/visualizations/{qlik_chart_object_id}/data"
headers = {
    "Authorization": "Basic " + base64.b64encode(f"{qlik_username}:{qlik_password}".encode()).decode()
}
response = requests.get(qlik_data_url, headers=headers)

# Check for successful response status
if response.status_code == 200:
    try:
        chart_data = response.json()
    except requests.exceptions.JSONDecodeError as e:
        print(f"Error decoding JSON: {e}")
        chart_data = None
else:
    print(f"Failed to fetch chart data. Status code: {response.status_code}")
    chart_data = None

# Convert Qlik chart data to a Pandas DataFrame
df = pd.DataFrame(chart_data)

# Data processing or analysis
# For this example, let's just plot the data and save it as a PDF
plt.figure(figsize=(10, 6))
plt.bar(df['Manager'], df['Sales'])
plt.xlabel('Manager')
plt.ylabel('Sales')
plt.title('Bar Chart Data from Qlik Sense')

# Save the plot as a PDF file
pdf_file_path = "qlik_bar_chart.pdf"
plt.savefig(pdf_file_path, format='pdf')

# Display or further process the DataFrame as needed
print(df.head())

  

 

Please, I will appreciate anyone that can really help

Labels (2)
1 Reply
F_B
Specialist II
Specialist II

 

The authorization Issue suggests that your authentication credentials are incorrect or that the API endpoint requires a different method of authentication.

The KeyError in Pandas DataFrame suggests that the column 'Manager' does not exist, which could be due to incorrect data parsing or an unexpected data structure.

 

Hope this helps