no save
Assistance
Achat
News

Forum | programmation
[CGI][Python] Problème avec fichiers binaires
sebsauvage, le mar. 01 juil. 2003 à 15:00:56
ayé. J'ai trouvé.

Sous tous les Unix, stdout est ouvert en mode binaire.
Mais pas sous Windows.
Il faut donc forcer stdout en mode binaire.
Le CGI devient:


import sys
import cgitb; cgitb.enable()

if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

sys.stdout.write('Content-Type: application/octet-stream\r\n')
sys.stdout.write('\r\n')
data = open('toto.zip','rb').read()
sys.stdout.write(data)

Et ça marche !
Ouf.

(Référence: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443 )
Précédentsebsauvage
juil. 03
lof.
juil. 03
Suivant
REPONSES
batmat
juil. 03
sebsauvage
juil. 03
sebsauvage
juil. 03
sebsauvage
juil. 03
lof.
juil. 03
batmat
juil. 03
sebsauvage
juil. 03
sebsauvage
juil. 03
Marden
juil. 03
sebsauvage
juil. 03
Version Web
Réalisé par RedShift
no save