wkhtmltopdf in python script is not working with cronjob - python

I am getting the below error while running python script as cronjob. But its working while executing manually.
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/pdfkit/configuration.py", line 21, in __init__
with open(self.wkhtmltopdf) as f:
FileNotFoundError: [Errno 2] No such file or directory: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/aws_security_cost_audit.py", line 626, in <module>
File "/home/ubuntu/aws_security_cost_audit.py", line 621, in main
File "/home/ubuntu/aws_security_cost_audit.py", line 95, in html_to_pdf
File "/usr/local/lib/python3.4/dist-packages/pdfkit/api.py", line 47, in from_file
configuration=configuration, cover_first=cover_first)
File "/usr/local/lib/python3.4/dist-packages/pdfkit/pdfkit.py", line 42, in __init__
self.configuration = (Configuration() if configuration is None
File "/usr/local/lib/python3.4/dist-packages/pdfkit/configuration.py", line 27, in __init__
'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
The file /usr/local/bin/wkhtmltopdf is executable and paths are exported by default.
root#jump-box:/home/ubuntu# whereis wkhtmltopdf
wkhtmltopdf: /usr/local/bin/wkhtmltopdf
root#jump-box:/home/ubuntu# which wkhtmltopdf
/usr/local/bin/wkhtmltopdf
root#jump-box:/home/ubuntu# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
Any guess on what could be the issue?

If I add this job:
* * * * * echo $PATH >> /ws/tmp.log 2>&1
then:
> cat tmp.log
/usr/bin:/bin
So you probably want to wrap your cronjob in a script that sets up the environment properly

Related

client_secrets.json not found in pyiinstaller

so I have this program in python that I want to use pyinstaller to make into an executable. It runs perfectly on its own and pyinstaller makes the executable fine but when I run the executable I get this:
Traceback (most recent call last):
File "site-packages/pydrive/auth.py", line 386, in LoadClientConfigFile
File "site-packages/oauth2client/clientsecrets.py", line 165, in loadfile
File "site-packages/oauth2client/clientsecrets.py", line 125, in _loadfile
oauth2client.clientsecrets.InvalidClientSecretsError: ('Error opening file',
'client_secrets.json', 'No such file or directory', 2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "updating.py", line 17, in <module>
File "site-packages/pydrive/auth.py", line 113, in _decorated
File "site-packages/pydrive/auth.py", line 443, in GetFlow
File "site-packages/pydrive/auth.py", line 366, in LoadClientConfig
File "site-packages/pydrive/auth.py", line 388, in LoadClientConfigFile
pydrive.settings.InvalidConfigError: Invalid client secrets file ('Error
opening file', 'client_secrets.json', 'No such file or directory', 2)
[34574] Failed to execute script updating
Why does this work on its own but pyinstaller doesn't catch anything until the executable is ran? I can't seem to find an answer otherwise.
Notable Info:
I'm running a Mac OS X, Mojave 10.14.2, Python Version 3.7.2.
The client_secrets.json is from a Google Drive API, v3
The file is in my directory just like all my other files, in the same spot.
Thanks!!

Tensorflow download_and_convert_mnist_m.py No such file or directory: '~/dsn_data/mnist_m/mnist_m_train'

I have a weird error message using the download_and_convert_mnist_m.py script from github https://github.com/tensorflow/models/tree/master/research/domain_adaptation/datasets.
The command I am using from the models/research/ folder is
python domain_adaptation/datasets/download_and_convert_mnist_m.py --dataset_dir=~/dsn_data/
The error message is
Traceback (most recent call last):
File "domain_adaptation/datasets/download_and_convert_mnist_m.py", line 237, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "domain_adaptation/datasets/download_and_convert_mnist_m.py", line 233, in main
run(FLAGS.dataset_dir)
File "domain_adaptation/datasets/download_and_convert_mnist_m.py", line 201, in run
os.path.join(dataset_dir, 'mnist_m', 'mnist_m_train'))
File "domain_adaptation/datasets/download_and_convert_mnist_m.py", line 177, in _get_filenames
for filename in os.listdir(dataset_dir):
OSError: [Errno 2] No such file or directory: '~/dsn_data/mnist_m/mnist_m_train'
I tried several ways:
without creating the path before and without having the data before
create the path before and let it empty
download and unpack data from https://drive.google.com/drive/folders/0B_tExHiYS-0vR2dNZEU4NGlSSW8 at the specified path as described here https://github.com/tensorflow/models/tree/master/research/domain_adaptation
I use
Ubuntu 16.04
Python 2.7
tensorflow 1.4.1
What else can I do.. looks like an pretty simple error but I have no more ideas.
I solved it. The correct command is without the equal sign.
python domain_adaptation/datasets/download_and_convert_mnist_m.py --dataset_dir=~/dsn_data/

How to run Openscad from windows command prompt

I am trying to run OpenScad through command prompt in windows 7. However I could not get it worked.
I added following directory to Path
"C:\Program Files\OpenSCAD\"
And tried to run the following script:
from os import listdir
from subprocess import call
files = listdir('.')
for f in files:
if f.find(".scad") >= 0: # get all .scad files in directory
of = f.replace('.scad', '.stl') # name of the outfile .stl
cmd = 'call (["openscad.com", "-o", "{}", "{}"])'.format(of, f) #create openscad command
exec(cmd)
Also I tried it with openscad, openscad.exe, openscad.com, no success so far.
The error I am getting is:
Traceback (most recent call last):
File "C:\Users\Desktop\scad2stl.py", line 9, in <module>
exec(cmd)
File "<string>", line 1, in <module>
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 247, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 955, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The specified file could not be found
Any suggestions?
I just saw this thread, I have make it work usign windows power shell, couldn't make it work on cmd due. So for example this doesn't work on cmd>
openscad -o render.png --imgsize=2048,2048 assembly.scad
but it does work on power shell (notice the ./ in the bigining):
./openscad -o render.png --imgsize=2048,2048 assembly.scad
hope it helps.
Best regards

Django: ValueError: Unable to configure handler - [Errno 2]

I am very new to Python and Django and is currently busy learning myself through tutorials on www.djangoproject.com. I am using PyCharm and working on OS X El Capitan. I have imported a project from GitHub and created a virtual environment for the project interpreter based on Python 3.5.1. In the vm I installed django.
I then activated the vm.
Now.. I started by trying to execute simple commands in the terminal like python manage.py startapp deonapp and python manage.py runserver but each time I get an error which I pasted below.. What did I miss? I cannot seem to find the /log/ directory?
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 558, in configure
handler = self.configure_handler(handlers[name])
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 731, in configure_handler
result = factory(**kwargs)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 1008, in __init__
StreamHandler.__init__(self, self._open())
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 1037, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log/debug.log'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/utils/log.py", line 75, in configure_logging
logging_config_func(logging_settings)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 795, in dictConfig
dictConfigClass(config).configure()
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 566, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'file': [Errno 2] No such file or directory: '/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log/debug.log'
I managed to fix it. The log directory was not created because it was excluded in the .gitignore file. I completely forgot to look what was excluded :). I created the directory manually and now it passed the error.
Deon
you can add this in setting.py
LOG_PATH = os.path.join(BASE_DIR, 'log')
or
if not os.path.join(LOG_PATH):
os.mkdir(LOG_PATH)
Other answers can be true in most of cases, But In my case log directory was created, But log dir had permission issue to my user. simply using chown to my user (my case www-data) solved the problem.
(In my case):
sudo chown www-data:www-data /var/log/django/
use your username:user-group instead of www-data:www-data and your log dir instead of /var/log/django/.
Traceback says, that it's no "log" directory.
Create directory with name log in path /Users/deon/Documents/PyCharmProjects/Developments/deonproject/
Create empty file .gitkeep
After creating .gitkeep file, push it to GitHub

Unable to get a pdf file from executing pyreport

We have been asked to generate a report using pyreport, but anytime I run the command pyreport last.py in command prompt I get these feedback:
Traceback (most recent call last):
File "C:\Python27\Scripts\pyreport-script.py", line 9, in <module>
load_entry_point('pyreport==0.3.4c', 'console_scripts', 'pyreport')()
File "C:\Python27\lib\site-packages\pyreport-0.3.4c-py2.7.egg\pyreport\pyreport.py", line 52, in commandline_call
pyfile = open(args[0],"r")
IOError: [Errno 2] No such file or directory: 'last.py'
Please help me solve this problem. i also already have latex installed on my computer does it have anything to do with this problem?

Categories