Simply return some (markdown) string in flask:
@app.route("/raw/", methods=['GET'])
def sometext():
return "This is an **example**"
## Main procedure
if __name__ == "__main__":
app.run(debug=True, port=8000)
If you call pandoc directly (pandoc http://localhost:8000/raw
) or with subprocess
, you get no problem:
import subprocess, os
url = "http://localhost:8000/raw"
pbody = subprocess.run(["pandoc", url], check=True, stdout=subprocess.PIPE)
print(pbody.stdout.decode())
But if you call pandoc within flask method:
@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
Then when you access to http://localhost:8000/get
you get Responsetimeout error from pandoc:
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
References: url_for in flask API