wkhtmltopdf not creating pdf in Heroku - python

I have a Python Flask project that uses the pdfkit module (and by extension wkhtmltopdf) to convert a locally stored HTML file into a .pdf file.
I have the whole thing working perfectly when it is hosted locally on my windows computer.
However after uploading my project folder to a Heroku instance and testing it - I received two errors (one of which I solved) when running through the program.
Note that I included wkhtmltopdf into my build pack before creating the Heroku instance with the following commands in Git (These were taken from Method 2 in: https://razorjack.net/wkhtmltopdf-on-heroku-evaluating-different-installation-options/):
I'll display them here as well:
heroku buildpacks:add https://github.com/dscout/wkhtmltopdf-buildpack.git
heroku config:set WKHTMLTOPDF_VERSION="0.12.4"
The first error that I solved involved pdfkit not being able to find the wkhtmltopdf binary in the Herkou instance. I eventually found it placed in the bin folder of my project - I added this to the pdfkit configuration path in my python file.
The problem that I'm now having is that the wkhtmltopdf/ pdfkit says it has created the .pdf file (I can see this from the output of the log tail on Git) but when I check the directory in the project folder on Heroku using the Heroku Terminal the .pdf doesn't appear to exist.
Interestingly when I try to 'touch' or create a new file in the /app folder in the instance nothing appears. But when I do the same in the /tmp folder it does. I have tried to point the wkhtmltopdf file.pdf creation to the /tmp folder but once again nothing appears to have been created.
If anybody could give me any helpful insight or a solution to why I might be having this problem I would be very grateful.
Thanks.

The problems you are facing may be caused by Heroku's ephemeral file system. Maybe this page of docs will help you find the solution.

Related

I'm trying to upload the bot to heroku server, I get this error:

I can't solve this problem, could it be my mistake?
Errors:
My files:
Your screenshot shows a file that appears to be called parser_twitter, but Windows recognizes it as a Python file. Similarly, chromedriver doesn't have a visible extension, but Windows recognizes it as an executable.
This suggests that Windows Explorer is hiding known file extensions. Those files are almost certainly really named parser_twitter.py and chromedriver.exe.
But your requirements.txt and runtime.txt file extensions are visible. That would mean they are actually called requirements.txt.txt and runtime.txt.txt.
I suggest turning off that "feature" so you can see what your files are actually called:
In File Explorer under View, in the Show/hide group, select the File name extensions check box.
Rename those files to remove the duplicate file extensions, commit, and redeploy.
Aside: If you have committed the chromedriver.exe file you're going to find that it doesn't work on Heroku. See Selenium web driver can't open browser on Heroku, for example.
Did you add the Python buildpack on your app? You can try checking it on the site or just run $ heroku buildpacks -app <your app name> if its not in there add it by running $ heroku buildpacks:set heroku/python -a <your app name>

Running move and delete commands on Heroku CLI

I've recently deployed an application to Heroku. Due to the constraints of the file system I'm looking to replace two css files within a Flask Package upon the application starting.
My main goal is to take a file from the app directory (the file is part of the git repo) and use it to replace a python package file located in the site packages directory.
I've tried to run the following from the Heroku CLI but nothing seems to happen.
heroku run mv ./bootstrap.css ./.heroku/python/lib/python3.6/site-packages/flask_bootstrap/static/css/bootstrap.css
I've also tried to remove the files from the site packages directory using RM but again nothing happens.
Could you please let me know if standard unix commands work on Heroku?
Fork and edit flask_bootstrap and add that to requirements.txt file like this.
Heroku using ephemeral filesystem. Whatever change you made to your filesystem only last until the dyno is restarted.
So my opinion is to change the file in your local repo and push to heroku again.
Source : https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted

how to deploy a vuejs/flask project on apache

I've created a simple project with vuejs as the frontend and flask as backend.
The project was constructed by following the example here, thus the resultant file structure is like that the vuejs build files "dist" is on the same folder as that of the driving python script, run.py.
The project was tested and working fine locally now I ran into problems trying to deploy it on my Ubuntu server hosted by digitalocean.
I followed this article to learn how to deploy - the article was well written but I believed I need to change the apache config file (/etc/apache2/sites-available/000-default.conf) a little to specify the static files of my project as shown in the screenshot.
The question is how? I don't know. When I followed the article word by word and launched the web app, it showed errors like:
Loading failed for the <script> with source “http://my_website.com/static/js/manifest.0e78d562f6b86d93f516.js”. vue-amazon:1:1
static is a standard vuejs folder under "dist" in my file structure.
I found the issue has nothing to do with the way how Flask project is deployed - it's about the configuration of the vuejs frontend.
I need to adjust the setting of assetsPublicPath in vuejs's config file, to a proper location where the index.html can find the obfuscated javascripts.
For example, if my project is called "ABC", and i want the url looks like:
http://my-site.com/ABC
I need to have this in the vuejs config file:
env: require('./prod.env'),
index: path.resolve(__dirname, '../../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '../../ABC/dist/',
before I run
npm run build

Django uwsgi subprocess and permissions

I'm trying to generate PDF file from Latex template. I've done it in development environment (running python manage.py straight from eclipse)... but I can't make it work into the server, which is running using cherokee and uwsgi.
We have realized that open(filename) creates a file owning to root (also root group). This isn't taking place in development environment... but the most strange thing about this issue is that somewhere else in our code we are creating a text file (latex uses is a text file too), but it's created with the user cherokee is supposed to use, not root!
What happened? How can we fix it?
We are running this code on ubuntu linux and a virtual environment both in development and production.
We started following some instructions to do it using python's temporary file and folder creation functions, but we thought that it could be something related with them, and created them "manually" in order to try to solve this issue... but it didn't work.
As I've said in my comments this issue was related to supervisord. I've solved it assigning the right path and user into "environment" variable of supervisord's config file.

could not save preference file google-apps-engine

Just installed Google Apps Engine and am getting "could not save" errors.
Specifically if I go in to preferences I get
Could not save into preference file
C:\Usera\myname/Google\google_appengine_launcher.ini:No such file or directory.
So some how I have a weird path, would like to know where and how to change this. I have search but found nothing, I have done a repair reinstall of GAE
Can find nothing in the registry for google_appengine_launcher.ini
I first saw the error when I created my first Application
Called hellowd
Parent Directory: C:\Users\myname\workspace
Runtime 2.7 (PATH has this path)
Port 8080
Admin port 8080
click create
Error:
Could not save into project file
C:\Users\myname/Google\google_appengine_launcher.ini:No such file or directory.
Thanks
I think I have found the answer to my own question.
I have a small app I have written to backup my stuff to Google Drive, this app would appear to have an error in it that does not stop it from running but does cause it to make a file called
C:\Usera\myname\Google
Therefore GAE can not create a directory called C:\Usera\myname/Google nor a file called C:\Usera\myname/Google\google_appengine_launcher.ini
I deleted the file Google, made a directory called Google and ran the GAE, saved pereferences and all working

Categories