Blog / Python

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 …

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 …

PyCon 2011 Atlanta

March 31, 2011

We attended the PyCon 2011 in Atlanta, GA early this month, which is the longest conference I’ve ever attended (March 9-17, 9 days total) but it was so worth it! We’re mainly a Java shop and we’re fairly new to Python so PyCon really showed us what we can do with Python and all these tools available for it that could really help us with our development. After the conference we’re pretty much convinced that …

How to log to multiple log files with log4j

March 6, 2011

Back to Java coding!

We have a Java application that calls an external application and since it gets called quite often we figured we should probably log its standard output and standard error streams to a separate log file so we could easily locate issues with it later. This would also allow us to create a different message format for it and different handlers.

Luckily, it turned out that this is pretty easy to do …