我有以下代码。当我运行它时,我收到以下错误:
File "app.py", line 16
@app.route('/')
^
SyntaxError: invalid syntax
当我删除这些行
时try:
tree = ET.parse('export.xml')
root = tree.getroot()
我没有错误了。我不明白这是什么问题,我该如何解决它。
from flask import Flask, render_template
import xml.etree.ElementTree as ET
import requests
import json
app = Flask(__name__)
file = open("/home/ubuntu/flaskapp/export.xml", 'w')
file.write(r.text)
file.close()
try:
tree = ET.parse('export.xml')
root = tree.getroot()
@app.route('/')
def hello_world():
return 'Hello from Flask!'
if __name__ == "__main__":
app.run()
答案 0 :(得分:0)
除了尝试之外,代码现在可以使用了。
from flask import Flask, render_template
import xml.etree.ElementTree as ET
import requests
import json
app = Flask(__name__)
file = open("/home/ubuntu/flaskapp/export.xml", 'w')
file.write(r.text)
file.close()
try:
tree = ET.parse('export.xml')
root = tree.getroot()
except Exception :
print "The database is stopped!\n"
@app.route('/')
def hello_world():
return 'Hello from Flask!'
if __name__ == "__main__":
app.run()