UnicodeError when running Python script via macOS LaunchAgent

If you are getting UnicodeErrors when reading/manipulating files using a Python script launched by a LaunchAgent or crontab, the problem might lie in the “current locale encoding”. Sample script Let’s assume you have the following code in a script set up to be launched by a LaunchAgent (also see my article on LaunchAgents): with open(some_path_to_file) as f: f.read() Let’s also assume that some_path_to_file points to a txt file containing some emojis (hey, why not? 😎) or some other unicode characters. ...

December 7, 2018

Watch a log file and send new lines to an HTTP endpoint – with log2http

Recently, I wanted to watch a couple of log files for new entries and have them sent to an http endpoint for collection and later analysis. I did a quick research on what tools exist, but eventually decided to create a small Python app myself which doesn’t require a complicated setup. I thought of something along the lines of: pip install <the module> Define which log files to watch and where to send the contents to Run it from the terminal. And so I built it. ...

October 20, 2018

python-fmrest compatibility with the new FileMaker 17 Data API

A few hours ago FileMaker 17 was released, and with it an updated Data API, which is now finally out of trial phase. Depending on your situation and if you have used the Data API in v16, there’s good and bad news. The bad news is that all API paths have been renamed, response formats have changed, authentication works a little different, and a few other little changes here and there. The good news is: if you have been using my python-fmrest wrapper library, little to no adjustments are necessary to make your existing app compatible with FileMaker 17 😎. If you have not used the library but have an app that you need to update, you might still be interested in reading a bit further to get a summary of the changes. ...

May 15, 2018

Using launchd agents to schedule scripts on macOS

Even though launchd has been around for quite some time now, I was still using crontab for scheduling some of my scripts until recently. Since launchd LaunchAgents can do much more and don’t expect your computer to be running at all times, it’s time to start using them more 😎. Let’s see how we can easily set up a LaunchAgent to run a Python script for the current user in regular intervals: ...

March 13, 2018

Load password protected Excel files into Pandas DataFrame

When trying to read an Excel file into a Pandas DataFrame gives you the following error, the issue might be that you are dealing with a password protected Excel file. pd.read_excel(PATH) [...] XLRDError: Can't find workbook in OLE2 compound document There seems to be no way of reading password protected files with xlrd. xlwings for the rescue Fortunately, there is xlwings, which lets you interact with the Excel application itself (via pywin32 or appscript). ...

February 21, 2018