Python Heroku允许推送的.exe运行-OSError:[Errno 13]权限被拒绝 [英] Python Heroku allow pushed .exe to run - OSError: [Errno 13] Permission denied
问题描述
我必须将.exe文件推送到heroku才能创建发票pdf.它在本地工作正常,没有任何问题,但是在heroku上我遇到了一个错误:
I had to push an .exe file to heroku to be able to create invoice pdfs. It works localy without any problems but on heroku I get an error:
OSError: [Errno 13] Permission denied
可能是因为不允许执行.exe文件.因此,我需要以某种方式创建允许该文件执行的规则.
Probably because I am not allowed to execute .exe files. So I need somehow to create a rule that this file is allowed to execute.
我将wkhtmltopdf.exe
推到了heroku,并用我的方法访问了此文件以创建pdf:
I pushed wkhtmltopdf.exe
to heroku and I access this file in my method to create a pdf:
MYDIR = os.path.dirname(__file__)
path_wkthmltopdf = os.path.join(MYDIR + "/static/executables/", "wkhtmltopdf.exe")
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
尚无法找到解决方案.
尝试通过heroku bash授予chmod权限,并添加了linux可执行文件,但仍然存在相同的错误:
Tryed giving permission with chmod through heroku bash and also adding a linux executable but still the same error:
~/static/executables $ chmod a+x wkhtmltopdf-linux.exe
~ $ chmod a+x static/executables/wkhtmltopdf-linux.exe
使用sudo给了我
bash: sudo: command not found
推荐答案
好吧,我设法用一个buildpack来解决这个问题.另外,必须安装wkhtmltopdf-pack
并将其添加到requirements.txt
.
Okay I managed to fix this with a buildpack. In addition wkhtmltopdf-pack
must be installed and added to the requirements.txt
.
然后,您必须在heroku中为wkhtmltopdf可执行文件设置一个配置变量,该可执行文件将从buildpack中提供的文件中生成.不要搜索.exe文件.
Then you have to set a config var in heroku for the wkhtmltopdf executable which will be generated from the files provided in the buildpack. Do not search for an .exe file.
heroku config:set WKHTMLTOPDF_BINARY=wkhtmltopdf-pack
您还可以在heroku仪表板中的设置下看到所有配置变量,也可以在其中创建它而不使用CLI.
You can see all your config vars also in the heroku dashboard under settings, you can also create it there and not use the CLI.
然后,您必须告诉pdfkit配置在哪里找到WKHTMLTOPDF_BINARY
:
Then you have to tell the pdfkit configuration where to find the WKHTMLTOPDF_BINARY
:
在我的config.py中:
In my config.py:
import subprocess
WKHTMLTOPDF_CMD = subprocess.Popen(
['which', os.environ.get('WKHTMLTOPDF_BINARY', 'wkhtmltopdf')], # Note we default to 'wkhtmltopdf' as the binary name
stdout=subprocess.PIPE).communicate()[0].strip()
对于pdfkit配置:
For the pdfkit configuration:
config = pdfkit.configuration(wkhtmltopdf=app.config['WKHTMLTOPDF_CMD'])
现在您应该可以创建pdf了,例如:
Now you should be able to create the pdf, example:
the_pdf = pdfkit.from_string("something", False, configuration=config)
本教程的功劳: https://artandlogic.com/2016/12/generating-pdfs-wkhtmltopdf -heroku/
这篇关于Python Heroku允许推送的.exe运行-OSError:[Errno 13]权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!