0

After testing our Flask api on our local system, I have been unable to run the same app after deploying on IIS server. Basically it gives me 500 error whenever I use pypandoc, but when I remove it app works. You can consider the following simple snippet with pypandoc :

from flask import Flask  
app = Flask(__name__)  
import os  
import pypandoc  
#path= pypandoc.get_pandoc_path()  
os.environ.setdefault('PYPANDOC_PANDOC','C:\\Pandoc\\pandoc.exe')


@app.route("/")  
def home():  
note =*** any html string *** 

rtf_string = pypandoc.convert_text(note, 'rtf', format='html')  
return rtf_string  

if __name__ == "__main__":  
app.run()  

Earlier I was getting the following error before setting 'PYPANDOC_PANDOC'

{"message": "Failed to Insert Data. No pandoc was found: either install pandoc and add it to your PATH or or call pypandoc.download_pandoc(...) or install pypandoc wheels with included pandoc.", "status": 0}

But I followed the following links and that error went away : Flask cannot find Pandoc on Linux Server (nginx+uwsgi)

Now I get the following error page : enter image description here

GauravKB
  • 11
  • 2
  • I'm not familiar with python, but according to your description, it seems that when you published your app to IIS, then your app didn't have python packages to realize the feature as you indicated that everything's ok in your local side. So could you pls follow [this document](https://learn.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019) to install related modules or packages and do some configuration in web config file. – Tiny Wang Nov 25 '21 at 05:49
  • Well no. Everything works fine on IIS (for all the other modules) except when it tries to use pypandoc module it gives me 500 error. – GauravKB Nov 25 '21 at 07:20
  • Try deleting 5-line asteric and replace ```'C:\\Pandoc\\pandoc.exe'``` by ```path``` – user11717481 Nov 29 '21 at 01:58

1 Answers1

1

Basically what was found is that after deploying on the IIS server pypandoc was simply unable to locate pandoc.exe file. This was not the case while testing locally. I got rid of pypandoc library altogether, and used python subprocess to access pandoc.exe directly. But still RTF to HTML conversion is kinda lossy with Pandoc. If the RTF file has complicated data such tables and images then it all gets lost or distorted.

GauravKB
  • 11
  • 2
  • [Open an issue](https://github.com/jgm/pandoc/issues/new) and attach example files so we can take a look. – tarleb May 12 '22 at 21:01