broadfield-dev commited on
Commit
561f193
·
verified ·
1 Parent(s): 161fe3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -10,7 +10,7 @@ from pygments import highlight
10
  from pygments.lexers import get_lexer_by_name
11
  from pygments.formatters import HtmlFormatter
12
  from pygments.styles import get_all_styles
13
- import uuid # <--- REQUIRED CHANGE 1: Import uuid
14
 
15
  app = Flask(__name__)
16
 
@@ -135,10 +135,14 @@ def convert_endpoint():
135
  include_fontawesome=data.get('include_fontawesome', False)
136
  )
137
 
138
- # Define options for wkhtmltoimage, removing the unsupported --no-cache
139
- options = {"quiet": "", 'encoding': "UTF-8"}
 
 
 
 
140
 
141
- # --- REQUIRED CHANGE 2: Manually create and use a temporary file ---
142
  temp_html_path = os.path.join(TEMP_DIR, f"{uuid.uuid4()}.html")
143
  with open(temp_html_path, "w", encoding="utf-8") as f:
144
  f.write(full_html)
@@ -161,7 +165,7 @@ def convert_endpoint():
161
  traceback.print_exc()
162
  return jsonify({'error': f'Failed to convert content: {str(e)}'}), 500
163
  finally:
164
- # --- REQUIRED CHANGE 3: Clean up the temporary file ---
165
  if temp_html_path and os.path.exists(temp_html_path):
166
  os.remove(temp_html_path)
167
 
 
10
  from pygments.lexers import get_lexer_by_name
11
  from pygments.formatters import HtmlFormatter
12
  from pygments.styles import get_all_styles
13
+ import uuid
14
 
15
  app = Flask(__name__)
16
 
 
135
  include_fontawesome=data.get('include_fontawesome', False)
136
  )
137
 
138
+ # Define options for wkhtmltoimage, adding error handling for network resources
139
+ options = {
140
+ "quiet": "",
141
+ 'encoding': "UTF-8",
142
+ 'load-error-handling': 'ignore'
143
+ }
144
 
145
+ # Manually create and use a temporary file
146
  temp_html_path = os.path.join(TEMP_DIR, f"{uuid.uuid4()}.html")
147
  with open(temp_html_path, "w", encoding="utf-8") as f:
148
  f.write(full_html)
 
165
  traceback.print_exc()
166
  return jsonify({'error': f'Failed to convert content: {str(e)}'}), 500
167
  finally:
168
+ # Clean up the temporary file
169
  if temp_html_path and os.path.exists(temp_html_path):
170
  os.remove(temp_html_path)
171