链接 Qlik Cloud 的详细 python 脚本

问题描述 投票:0回答:1

我正在尝试生成详细的 python 脚本来从 Qlik 云条形图读取数据,将其作为 pdf 文件输出到我的笔记本电脑上,但我不断收到错误消息 401。即无法获取数据。 以下是错误:

Failed to fetch data. Status code: 401 Traceback (most recent call last): File "c:\Users\Sunday\Documents\ClikModules\appv3ntpj.py", line 41, in <module> plt.bar(df['Customer'], df['Sum(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: 'Customer'

这是我写的代码。我希望它从 qlik sense 服务器读取 Json 格式的文件并将其输出为 pdf 给我

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

# Qlik Sense Configuration
qlik_base_url = "https://ioco2.eu.qlikcloud.com/"
qlik_app_id = "d0c200c8-b3bb-4157-81b7-4d18d44856a3"
qlik_table_object_id = "tNfNKkC"

# Authentication credentials (replace with your actual credentials)
qlik_username = "my username"
qlik_password = "password"

# Fetch data from Qlik Sense with authentication headers
qlik_data_url = f"{qlik_base_url}/api/v1/apps/{qlik_app_id}/tables/{qlik_table_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:
        table_data = response.json()
    except requests.exceptions.JSONDecodeError as e:
        print(f"Error decoding JSON: {e}")
        table_data = None
else:
    print(f"Failed to fetch data. Status code: {response.status_code}")
    table_data = None

# Continue with the rest of the script...

# Convert Qlik table data to a Pandas DataFrame
df = pd.DataFrame(table_data)

# Data processing or analysis (replace this with your specific requirements)
# For this example, let's just plot the data and save it as a PDF
plt.figure(figsize=(10, 6))
plt.bar(df['Customer'], df['Sum(Sales)'])
plt.xlabel('Customer')
plt.ylabel('Sum(Sales)')
plt.title('Top Customers by Sales in Qlik Sense')

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

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

请问,我能做什么我在 python 和 Qlik cloud 中没有做过的事情?

python-3.x pandas python-requests qliksense
1个回答
0
投票

根据 2022 年的 Qlik 社区帖子,这看起来像是 Qlik 已知错误:Qlik 数据网关连接重新加载失败,出现错误 401“研发部门已将此问题识别为缺陷,正在修复”

联系他们的支持人员,希望他们现在可以提供帮助。

© www.soinside.com 2019 - 2024. All rights reserved.