alphagov / alphagov/notifications-python-client
MS Excel opens CSV files with incorrect encoding
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 25
- Forks
- 23
- Merge medio
- 3 d 20 h
- PR fusionados (30 d)
- 1
Descripción
This issue is only tangentially related to the notify service, but I wanted to flag it for discussion.
When CSV files are opened by MS Excel, Excel assumes that the file is ASCII encoded - unless a Byte Order Mark is specified in the first 3 octets of the file to denote the encoding. Further details can be found here: https://stackoverflow.com/a/155176
The result of Excel assuming the incorrect encoding is that special characters are rendered incorrectly to the user.
Excel's behaviour here is quite different to other standard spreadsheet applications. Calc on Linux and Numbers on Mac do a pretty good job of automatically detecting the encoding of the file.
I believe that this issue is a good one to discuss now that the Notify service supports CSV file uploads/downloads fully with the addition of is_csv to prepare_upload.
A very simple idea that I have is to call this behaviour out in the client docs (there's a new section on CSV uploads) - in order to get ahead of this issue for developers that are looking to send CSVs from their apps.
Example Code: CSV which is badly rendered in Excel:
import io
from notifications_python_client import prepare_upload
from notifications_python_client.notifications import NotificationsAPIClient
notifications_client = NotificationsAPIClient("XXX")
csv_contents = 'Büyükdere Cad,foo,bar'
buf = io.BytesIO(csv_contents.encode('utf-8'))
file_content = prepare_upload(buf, is_csv=True)
notifications_client.send_email_notification(
email_address='foobar@example.net',
template_id='XXX',
personalisation={
'link_to_file': file_content,
},
)
Example Code: CSV which is rendered correctly in Excel:
import codecs
import io
from notifications_python_client import prepare_upload
from notifications_python_client.notifications import NotificationsAPIClient
notifications_client = NotificationsAPIClient("XXX")
csv_contents = 'Büyükdere Cad,foo,bar'
buf = io.BytesIO(codecs.BOM_UTF8 + csv_contents.encode('utf-8'))
file_content = prepare_upload(buf, is_csv=True)
notifications_client.send_email_notification(
email_address='foobar@example.net',
template_id='XXX',
personalisation={
'link_to_file': file_content,
},
)
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza localizando la sección de la documentación del cliente sobre las cargas de CSV y revisa cómo se explica actualmente prepare_upload con is_csv=True. Documenta, usando los ejemplos de este issue, que Microsoft Excel puede representar incorrectamente los CSV en UTF-8 sin una BOM UTF-8, y deja claras las indicaciones para los desarrolladores que envían archivos CSV.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100