Google Hangouts Chat incoming webhook using Python standard library only

The official docs on setting up an incoming webhook uses the third-party httplib2, which is not part of the Python 3.6 standard library. Here’s a quick snippet using only the standard library instead:

import json
import urllib.parse
import urllib.request

def main():
    # python 3.6

    bot_message = {'text': 'Hello from Python script!'}
    message_headers = {'Content-Type': 'application/json; charset=UTF-8'}

    byte_encoded = json.dumps(bot_message).encode('utf-8')
    req = urllib.request.Request(url=url, data=byte_encoded, headers=message_headers)
    response = urllib.request.urlopen(req)


if __name__ == '__main__':

Cartesian product in Python

A cartesian product operation can return a set of “combinations” based on given values, so for example I could have the following values:

a b c
1 1 1
  2 2

I would then expect the cartesian product operation to return something like a1b1c1, a1b1c2, a1b1c3, a1b2c1 and so on…

Many, many times have had to solve this problem over and over in Python… it’s time to jot down some notes.


Switching between Docker and VirtualBox on Windows 10

As outlined here, Docker for Windows requires Hyper-V. This needs to be disabled before you can run VirtualBox.

# Run from elevated prompt (admin privileges)
bcdedit /set hypervisorlaunchtype off

And to start using Docker for Windows again, re-enable Hyper-V:

# Run from elevated prompt (admin privileges)
bcdedit /set hypervisorlaunchtype auto

A reboot is required in both cases.

Note: if you only see 32-bit options when creating a VM in VirtualBox, it could be because you havent disabled Hyper-V. More info here on this issue.

Official PySide2 wheels!

The Qt Company has released official and pip-installable PySide2 wheel snapshots!

Simo posted the details today on the PySide mailing list, but in a nutshell:

pip install --index-url= pyside2 --trusted-host

Update 2018-04-05: official docs are now also online at Update 2018-07-17: PySide2 can now be installed from pip install PySide2!

Standalone PySide2 wheels

The Qt Company has yet to release official, standalone and pip-installable PySide2 wheels. However, since they made it possible to build standalone wheels successfully, I’m now building such unofficial, standalone wheels here using free CI services (thanks Travis and AppVeyor!):

Update 2018-03-09: The Qt Company now offers official and standalone wheels, read more here! Update 2018-07-17: PySide2 can now be installed from pip install PySide2!