PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : python file open binary speichern in mysql blob



jonasge
28-07-2005, 16:35
hallo

ich habe verschiedene files, einmal wav files und andermal sff files.

Diese will ich jetzt mit python in eine mysql DB in ein BLOB feld speichern.

Mein Code:
f_cs = open(filename, 'r')
fcsdata=f_cs.read().replace("\'","\\'")
f_cs.close()


Das .replace benutze ich um die \ terminieren, damit ichdas in dei DB eintragen kann. Nun werde leider mit diesem code die Bilder kaputt gemacht.
Wie kann ich das in python richtig einlesen?

Danke
Jonas

foobarflu
29-07-2005, 07:07
'rb' als Modus beim öffnen zu nehmen sollte helfen.

Wobei ich mich grad frage, wieso der docstring das nicht hergibt...

jonasge
29-07-2005, 16:08
Also bilddateien sind das format .sff und dann will ich noch Audiofiles speichern die sind .la Format.

Mit .la habe ich gerade probiert, dort kommt dann folgende Meldung:

Fri Jul 29 17:06:29 2005 Pythonscript 0x80ba968: Traceback: _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '@\xd0\xe0\x90\xac\x80\x1ev\x9b\x97\xa9y\xe9.(f\x8 8\x80\xe0\xc8\xd6\xa6\xd3\x87I\xa1\x19\xe9\xd7\x89 \x13&\x82\x92vN\xbf\x17\x99gv\n'\xf6(\xabC\x03\x03j\x93 \xdf\x02\xbe\xff\xa9\x07\x1a\xe2\x8a>\xa8\xe8")


Gruß
jonas

jonasge
29-07-2005, 16:09
Ne moeglichkeit waere noch das ganze base64 zu codieren und mit php wieder zu encodieren mit base64.


Oder?

Gruß
Jonas