Nginx : Address family not supported by protocol

19 Sep 2013

I was using nginx as a reverse proxy for a webapp and noticed some requests intermittently failed with a 500 error.

For instance, the following request always failed at first page load :

http://localhost/get_library/ 500 Internal Server Error 2ms

But subsequent requests worked perfectly :

http://localhost/get_library/ 200 OK 18ms

The nginx error log was the following :

[alert] 13131#0: *39 socket() failed (97: Address family not supported by protocol) while connecting to upstream, client:, server: localhost, request: "GET /get_library/ HTTP/1.1", upstream: "http://[::1]:8080/get_library/", host: "localhost", referrer: "http://localhost/"

The part that got my attention is http://[::1]:8080/get_library/ wich seems to indicate that localhost is resolved to ::1. As you probably know, it is localhost in ipv6.

As the ipv6 stack is disabled on my machine, I just changed my nginx conf from :

location ~ ^/(get|create)_(library|song) {
    proxy_pass http://localhost:8080;

to :

location ~ ^/(get|create)_(library|song) {

And it solved the problem !

Convert Excel CSV to UTF-8

30 Aug 2013

I recently had to work with a CSV file generated using Excel's export functionality. The problem was that it contained french text with accents but the encoding was something different than the usual UTF-8 or LATIN-1 I'm used to.

The file command didn't help much :

$ file -i export.csv
export.csv: text/plain; charset=unknown-8bit

After some investigation, I found out that the encoding used by Excel when generating this CSV was Windows-1252.

To convert the CSV file to UTF-8, I just ran this simple command :

$ iconv -f CP1252 -t UTF-8 export.csv > export-utf8.csv

I was then able to work with the new UTF-8 version of the file.

You can find the complete list of Windows code pages on Wikipedia and the corresponding iconv encodings by running iconv --list.