【发布时间】:2017-01-09 19:35:52
【问题描述】:
只需在烧瓶中返回一些(降价)字符串:
@app.route("/raw/", methods=['GET'])
def sometext():
return "This is an **example**"
## Main procedure
if __name__ == "__main__":
app.run(debug=True, port=8000)
如果您直接调用 pandoc (pandoc http://localhost:8000/raw) 或使用subprocess,则没有问题:
import subprocess, os
url = "http://localhost:8000/raw"
pbody = subprocess.run(["pandoc", url], check=True, stdout=subprocess.PIPE)
print(pbody.stdout.decode())
但是如果你在flask方法中调用pandoc:
@app.route("/get", methods=['GET'])
def index():
url = "{}".format(url_for('sometext', _external=True))
pbody = subprocess.run(["pandoc", url], check=True, stdout=subprocess.PIPE, universal_newlines=True)
print("***Error: ", pbody.stderr)
return pbody.stdout
然后,当您访问 http://localhost:8000/get 时,您会收到 pandoc 的 Responsetimeout 错误:
pandoc: HttpExceptionRequest Request {
host = "localhost"
port = 8000
secure = False
requestHeaders = []
path = "/raw/"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
ResponseTimeout
【问题讨论】:
标签: python flask subprocess pandoc