Search code examples
postgresqlpgadminpgadmin-4

pgadmin4 1.3 raises CSV export broken


I installed pgadmin4 1.3 (in a docker container) and everything is working fine except CSV exports.

I filled in Binary Paths properly in Preferences but it is still not working. I have no error message. When I click the CSV export icon nothing happens.

Here is my config:

  • Python version : 2.7.12
  • Postgresql version : 9.5
  • Pgadmin version : 4.1.3
  • Ubuntu 16.04

If someone has the same issue and hopefully knows how to solve it can you please help ?

Thanks !


Solution

  • I finally found the culprit !

    I had a look to /var/log/apache2/errors.log and saw an UnicodeEncodeError during CSV creation. Error came from this file :

    /usr/local/lib/python2.7/dist-packages/pgadmin4/pgadmin/utils/driver/psycopg2/__init__.py

    Line 651, the CSV writer was broken when writing special characters like accentuated characters (I am using Python 2, I guess I would not have had the issue with Python 3):

    csv_writer.writerows(results)

    Eventually I solved it by using the unicodecsv library :

    • pip install unicodecsv
    • line 22: replaced import csv with import unicodecsv as csv
    • line 647: replaced csv.DictWriter(res_io, fieldnames=header, delimiter=str(','), quoting=csv.QUOTE_NONNUMERIC) with csv.DictWriter(res_io, encoding='utf-8', fieldnames=header, delimiter=str(','), quoting=csv.QUOTE_NONNUMERIC)

    Hope it might help other people while this encoding bug is not fixed !