reportlab.pdfbase.ttfonts.TTFError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).
Is there any solution for the below error?
Hi @mitsuonagaoka,
Thank you for sharing your question with the community!
Your post is missing a code snippet and a link to your app’s GitHub repo. Please check out our guidelines on how to post an effective question here and update your post to help the community answer your question.
tonykip Developer Relations @Streamlit
Thank you immediately answer.
I am @mitsuonagaoka, 74 years old, living in Ibaraki, Japan.
I am studying Python and Streamit.
- Snippets (code fragments)
App Description
This app is to display the data of the app that manages sales sales.
The data is retrieved from a SQLite3 database and processed with pandas.
The processed result is created in a PDF file, previewed, and downloaded.
“”"
On Windows PowerShell, ‘streamlit run streamlit_sqlite3_02.py’
, you can preview and download normally, but Streamit App Deploy
I can’t preview or download.
- Link to GitHub repository
GitHub repository
That’s all, thank you very much.Vie the code.
streamlit run streamlit_sqlite3_02.py
import streamlit as st
import sqlite3
import pandas as pd
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
import os
import base64
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.fonts import addMapping
import locale
Connect to the SQLite database
conn = sqlite3.connect(“./data/product30.db”)
Read data from the table
query = “SELECT * FROM t_出荷Data”
df = pd.read_sql_query(query, conn)
Close the database connection
conn.close()
Set column headers in Japanese
df.columns = [“番号”, “品番”, “出荷数”, “注番”, “出荷日”, “出荷金額”]
st.title(‘Data Preview’)
Display data in dataframe
st.dataframe(df)
フォントファイルがアプリのディレクトリ内の fonts ディレクトリにある場合のパス
font_path = “fonts/msgothic.ttc”
Register custom font
pdfmetrics.registerFont(TTFont(“MS Gothic”, font_path))
addMapping(“MS Gothic”, 0, 0, “MS Gothic”)
Create PDF with borders
def create_pdf(dataframe):
pdf_filename = os.path.join(os.path.dirname(file), “output.pdf”)
doc = SimpleDocTemplate(pdf_filename, pagesize=A4, topMargin=20,
bottomMargin=20) # Set A4 size and margins
data = [df.columns.tolist()] + df.values.tolist()
Add borders to the table
table_style = TableStyle([(‘GRID’, (0, 0), (-1, -1), 1, colors.black),
(‘FONTNAME’, (0, 0), (-1, 0), “MS Gothic”), # Use the specified font name
(‘ALIGN’, (0, 0), (-1, -1), ‘CENTER’),
(‘BACKGROUND’, (0, 0), (-1, 0), colors.gray)])
table = Table(data)
table.setStyle(table_style)
doc.build([table])
return pdf_filename
pdf_file = create_pdf(df)
Display PDF preview
st.title(‘PDF Preview’)
with open(pdf_file, “rb”) as f:
base64_pdf = base64.b64encode(f.read()).decode(‘utf-8’)
st.markdown(
f’',
unsafe_allow_html=True)
Display PDF download link
st.markdown(f"Download PDF File")
2023年8月12日(土) 4:16 Tony Kipkemboi via Streamlit <notifications@streamlit.discoursemail.com>:
Hi @mitsuonagaoka,
Thanks for providing more details and congratulations on learning Python and Streamlit; so exciting! ![]()
From the initial error you posted reportlab.pdfbase.ttfonts.TTFError: This app has encountered an error; it’s most likely related to the custom font. Is the font working locally and not on Community Cloud deployment?
Can you also do a screen recording of where you’re getting the error? That might help with troubleshooting on our end.
Thank you.
Thank you for answering.
I tried again.
As before, there is no PDF preview and a new blank web page appears when you press the Download PDF file button.
Application management information is as follows.
reportlab.pdfbase.ttfonts.TTFError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).
Traceback:
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 552, in _run_script
exec(code, module.dict)
File “/mount/src/mitsu_web06/streamlit_sqlite3_02.py”, line 44, in
pdfmetrics.registerFont(TTFont(“ARIALNB”, font_path))
File “/home/adminuser/venv/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py”, line 1178, in init
self.face = TTFontFace(filename, validate=validate, subfontIndex=subfontIndex)
File “/home/adminuser/venv/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py”, line 1072, in init
TTFontFile.init(self, filename, validate=validate, subfontIndex=subfontIndex)
File “/home/adminuser/venv/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py”, line 439, in init
TTFontParser.init(self, file, validate=validate,subfontIndex=subfontIndex)
File “/home/adminuser/venv/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py”, line 175, in init
self.readFile(file)
File “/home/adminuser/venv/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py”, line 251, in readFile
self.filename, f = TTFOpenFile(f)
File “/home/adminuser/venv/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py”, line 161, in TTFOpenFile
raise TTFError(‘Can't open file “%s”’ % fn)
[ UTC ] Logs for mitsuweb06-smztdmthpqbjahbhikbxin.streamlit.app/mount/src/mitsu_web06/output.pdf
────────────────────────────────────────────────────────────────────────────────────────
[06:23:22]
Starting up repository: ‘mitsu_web06’, branch: ‘main’, main module: ‘streamlit_sqlite3_02.py’
[06:23:22]
Cloning repository…
[06:23:24]
Cloning into ‘/mount/src/mitsu_web06’…
Warning: Permanently added the ED25519 host key for IP address ‘192.30.255.113’ to the list of known hosts.
[06:23:24]
Cloned repository!
[06:23:24]
Pulling code changes from Github…
[06:23:25]
Processing dependencies…
──────────────────────────────────────── pip ───────────────────────────────────────────
Collecting streamlit
Downloading streamlit-1.25.0-py2.py3-none-any.whl (8.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.1/8.1 MB 131.7 MB/s eta 0:00:00[2023-08-18 06:23:26.739770]
Collecting pandas
Downloading pandas-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.4/12.4 MB 270.5 MB/s eta 0:00:00[2023-08-18 06:23:27.083924]
Collecting reportlab
Downloading reportlab-4.0.4-py3-none-any.whl (1.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.9/1.9 MB 294.4 MB/s eta 0:00:00[2023-08-18 06:23:27.468663]
Collecting pympler<2,>=0.9
Downloading Pympler-1.0.1-py3-none-any.whl (164 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 164.8/164.8 KB 224.5 MB/s eta 0:00:00[2023-08-18 06:23:27.530396]
Collecting rich<14,>=10.14.0
Downloading rich-13.5.2-py3-none-any.whl (239 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 239.7/239.7 KB 269.3 MB/s eta 0:00:00[2023-08-18 06:23:27.655054]
Collecting toml<2,>=0.10.1
Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting cachetools<6,>=4.0
Downloading cachetools-5.3.1-py3-none-any.whl (9.3 kB)
Collecting validators<1,>=0.2
Downloading validators-0.21.2-py3-none-any.whl (25 kB)
Collecting tenacity<9,>=8.1.0
Downloading tenacity-8.2.3-py3-none-any.whl (24 kB)
Collecting gitpython!=3.1.19,<4,>=3.0.7
Downloading GitPython-3.1.32-py3-none-any.whl (188 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 188.5/188.5 KB 239.8 MB/s eta 0:00:00[2023-08-18 06:23:27.894004]
Collecting blinker<2,>=1.0.0
Downloading blinker-1.6.2-py3-none-any.whl (13 kB)
Collecting click<9,>=7.0
Downloading click-8.1.7-py3-none-any.whl (97 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 KB 258.7 MB/s eta 0:00:00[2023-08-18 06:23:27.976116]
Collecting packaging<24,>=16.8
Downloading packaging-23.1-py3-none-any.whl (48 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.9/48.9 KB 198.8 MB/s eta 0:00:00[2023-08-18 06:23:28.029329]
Collecting tornado<7,>=6.0.3
Downloading tornado-6.3.3-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (427 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 427.7/427.7 KB 266.1 MB/s eta 0:00:00[2023-08-18 06:23:28.124334]
Collecting numpy<2,>=1.19.3
Downloading numpy-1.25.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.3/18.3 MB 261.2 MB/s eta 0:00:00[2023-08-18 06:23:28.597506]
Collecting protobuf<5,>=3.20
Downloading protobuf-4.24.0-cp37-abi3-manylinux2014_x86_64.whl (311 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 311.6/311.6 KB 252.3 MB/s eta 0:00:00[2023-08-18 06:23:29.007221]
Collecting typing-extensions<5,>=4.1.0
Downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Collecting pyarrow>=6.0
Downloading pyarrow-12.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (39.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 39.0/39.0 MB 281.1 MB/s eta 0:00:00[2023-08-18 06:23:29.335201]
Collecting importlib-metadata<7,>=1.4
Downloading importlib_metadata-6.8.0-py3-none-any.whl (22 kB)
Collecting pydeck<1,>=0.8
Downloading pydeck-0.8.0-py2.py3-none-any.whl (4.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.7/4.7 MB 164.4 MB/s eta 0:00:00[2023-08-18 06:23:29.545587]
Collecting watchdog>=2.1.5
Downloading watchdog-3.0.0-py3-none-manylinux2014_x86_64.whl (82 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 82.1/82.1 KB 222.8 MB/s eta 0:00:00[2023-08-18 06:23:29.666039]
Collecting altair<6,>=4.0
Downloading altair-5.0.1-py3-none-any.whl (471 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 471.5/471.5 KB 289.5 MB/s eta 0:00:00[2023-08-18 06:23:29.713367]
Collecting python-dateutil<3,>=2.7.3
Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 KB 271.5 MB/s eta 0:00:00[2023-08-18 06:23:29.756144]
Collecting pillow<10,>=7.1.0
Downloading Pillow-9.5.0-cp39-cp39-manylinux_2_28_x86_64.whl (3.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 285.9 MB/s eta 0:00:00[2023-08-18 06:23:30.195334]
Collecting tzlocal<5,>=1.1
Downloading tzlocal-4.3.1-py3-none-any.whl (20 kB)
Collecting requests<3,>=2.18
Downloading requests-2.31.0-py3-none-any.whl (62 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 KB 170.7 MB/s eta 0:00:00[2023-08-18 06:23:30.352723]
Collecting pytz>=2020.1
Downloading pytz-2023.3-py2.py3-none-any.whl (502 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 502.3/502.3 KB 280.6 MB/s eta 0:00:00[2023-08-18 06:23:30.530469]
Collecting tzdata>=2022.1
Downloading tzdata-2023.3-py2.py3-none-any.whl (341 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 341.8/341.8 KB 256.6 MB/s eta 0:00:00[2023-08-18 06:23:30.591658]
Collecting jinja2
Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 KB 248.8 MB/s eta 0:00:00[2023-08-18 06:23:30.683277]
Collecting toolz
Downloading toolz-0.12.0-py3-none-any.whl (55 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.8/55.8 KB 192.1 MB/s eta 0:00:00[2023-08-18 06:23:30.719896]
Collecting jsonschema>=3.0
Downloading jsonschema-4.19.0-py3-none-any.whl (83 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 83.4/83.4 KB 209.2 MB/s eta 0:00:00[2023-08-18 06:23:30.796626]
Collecting gitdb<5,>=4.0.1
Downloading gitdb-4.0.10-py3-none-any.whl (62 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.7/62.7 KB 166.5 MB/s eta 0:00:00[2023-08-18 06:23:30.852522]
Collecting zipp>=0.5
Downloading zipp-3.16.2-py3-none-any.whl (7.2 kB)
Collecting six>=1.5
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting urllib3<3,>=1.21.1
Downloading urllib3-2.0.4-py3-none-any.whl (123 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 123.9/123.9 KB 210.6 MB/s eta 0:00:00[2023-08-18 06:23:31.169961]
Collecting charset-normalizer<4,>=2
Downloading charset_normalizer-3.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 202.1/202.1 KB 249.2 MB/s eta 0:00:00[2023-08-18 06:23:31.318848]
Collecting certifi>=2017.4.17
Downloading certifi-2023.7.22-py3-none-any.whl (158 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 158.3/158.3 KB 230.9 MB/s eta 0:00:00[2023-08-18 06:23:31.369964]
Collecting idna<4,>=2.5
Downloading idna-3.4-py3-none-any.whl (61 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.5/61.5 KB 122.3 MB/s eta 0:00:00[2023-08-18 06:23:31.408170]
Collecting markdown-it-py>=2.2.0
Downloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.5/87.5 KB 186.4 MB/s eta 0:00:00[2023-08-18 06:23:31.474064]
Collecting pygments<3.0.0,>=2.13.0
Downloading Pygments-2.16.1-py3-none-any.whl (1.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 265.8 MB/s eta 0:00:00[2023-08-18 06:23:31.533792]
Collecting pytz-deprecation-shim
Downloading pytz_deprecation_shim-0.1.0.post0-py2.py3-none-any.whl (15 kB)
Collecting smmap<6,>=3.0.1
Downloading smmap-5.0.0-py3-none-any.whl (24 kB)
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Collecting rpds-py>=0.7.1
Downloading rpds_py-0.9.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 242.1 MB/s eta 0:00:00[2023-08-18 06:23:32.029348]
Collecting jsonschema-specifications>=2023.03.6
Downloading jsonschema_specifications-2023.7.1-py3-none-any.whl (17 kB)
Collecting attrs>=22.2.0
Downloading attrs-23.1.0-py3-none-any.whl (61 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 KB 219.9 MB/s eta 0:00:00[2023-08-18 06:23:32.113173]
Collecting referencing>=0.28.4
Downloading referencing-0.30.2-py3-none-any.whl (25 kB)
Collecting mdurl~=0.1
Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Installing collected packages: pytz, zipp, watchdog, validators, urllib3, tzdata, typing-extensions, tornado, toolz, toml, tenacity, smmap, six, rpds-py, pympler, pygments, protobuf, pillow, packaging, numpy, mdurl, MarkupSafe, idna, click, charset-normalizer, certifi, cachetools, blinker, attrs, requests, reportlab, referencing, pytz-deprecation-shim, python-dateutil, pyarrow, markdown-it-py, jinja2, importlib-metadata, gitdb, tzlocal, rich, pydeck, pandas, jsonschema-specifications, gitpython, jsonschema, altair, streamlit
Successfully installed MarkupSafe-2.1.3 altair-5.0.1 attrs-23.1.0 blinker-1.6.2 cachetools-5.3.1 certifi-2023.7.22 charset-normalizer-3.2.0 click-8.1.7 gitdb-4.0.10 gitpython-3.1.32 idna-3.4 importlib-metadata-6.8.0 jinja2-3.1.2 jsonschema-4.19.0 jsonschema-specifications-2023.7.1 markdown-it-py-3.0.0 mdurl-0.1.2 numpy-1.25.2 packaging-23.1 pandas-2.0.3 pillow-9.5.0 protobuf-4.24.0 pyarrow-12.0.1 pydeck-0.8.0 pygments-2.16.1 pympler-1.0.1 python-dateutil-2.8.2 pytz-2023.3 pytz-deprecation-shim-0.1.0.post0 referencing-0.30.2 reportlab-4.0.4 requests-2.31.0 rich-13.5.2 rpds-py-0.9.2 six-1.16.0 smmap-5.0.0 streamlit-1.25.0 tenacity-8.2.3 toml-0.10.2 toolz-0.12.0 tornado-6.3.3 typing-extensions-4.7.1 tzdata-2023.3 tzlocal-4.3.1 urllib3-2.0.4 validators-0.21.2 watchdog-3.0.0 zipp-3.16.2
WARNING: You are using pip version 22.0.3; however, version 23.2.1 is available.
You should consider upgrading via the ‘/home/adminuser/venv/bin/python -m pip install --upgrade pip’ command.
Checking if Streamlit is installed
Found Streamlit version 1.25.0 in the environment
────────────────────────────────────────────────────────────────────────────────────────
[06:23:45]
Python dependencies were installed from /mount/src/mitsu_web06/requirements.txt using pip.
Check if streamlit is installed
Streamlit is already installed
[06:23:47]
Processed dependencies!
Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.
2023年8月15日(火) 22:33 Tony Kipkemboi via Streamlit <notifications@streamlit.discoursemail.com>:
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.