Blog / Howto

How to convert a list of dictionaries to CSV format in Python

July 26, 2011

I was working on something last night where I needed to dump JSON data to a text file. I figured it might be a good idea to give an option to export it to a CSV file with headers as well so I wrote this simple function to do so:

import csv

def export_dict_list_to_csv(data, filename):
    with open(filename, 'wb') as f:
        # Assuming that all dictionaries in the list have the same keys.
        headers = sorted([k …

Windows Tip: Run applications in the background using Task Scheduler

July 21, 2011

I was working on a project a couple of weeks ago which involves Celery for processing tasks. I wanted the Celery process to run in the background as a service but it didn’t come with a Windows service installer, we will have to write our own. Since we were still just working on a proof of concept, I didn’t want to spend too much time on this at this point and then I realized I …

How to use client certificate authentication with Suds

July 15, 2011

This is related to my last post. I was finally able to communicate to an SSL-enabled SOAP service with my computer behind a proxy but then ran into another problem: certificate-based authentication.

Suds actually doesn’t support certificate authentication directly, but fortunately someone created a custom transport for it here.

I tried his code but then ran into connection issues again, I had to modify it a little bit to include the proxy settings …

How to connect to a SOAP-based web service with Suds over a proxy that requires authentication

July 14, 2011

I’m writing a small Python program to connect to a SOAP-based web service using Suds and just ran into an issue with authenticating to our proxy server. I’m able to connect fine if the web service runs on http, but the web service we need to connect to uses https and the urllib2 module threw an error:

urllib2.URLError: <urlopen error Tunnel connection failed: 407 Proxy Authentication Required>

The solution in my case is to upgrade …

How to enable Telnet on Windows 7

July 10, 2011

We have a computer at work that runs on Windows 7 and I needed to check whether it can connect to our internal SMTP server so I can use it to send emails. The quickest way to do this is to telnet to the SMTP server on port 25 but it turned out telnet is disabled/not installed by default on Windows 7. It gave the message “‘telnet’ is not recognized as an internal or external …