Update app.py
Browse files
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
|
| 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,
|
| 139 |
-
options = {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
#
|
| 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 |
-
#
|
| 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 |
|