Re: Error on base64.b64decode() ?!

2007-10-13 Thread Christoph Krammer
On 12 Okt., 17:09, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > If you get an incorrect padding error, try appending a "=" and decoding > again. If you get the error again, try appending one more "=". If it > still doesn't work, then you might be out of luck. This seems to work in some cases

Error on base64.b64decode() ?!

2007-10-12 Thread Christoph Krammer
Hello everybody, I am using a python script to extract images from email messages. This works fine for some messages, but not all attached images can be decoded. I use the following code to decode the image and save it to a database: try: imagedec = base64.b64decode(imageenc) imagehash = md5.

Re: MemoryError on reading mbox file

2007-09-13 Thread Christoph Krammer
On 12 Sep., 16:39, Istvan Albert <[EMAIL PROTECTED]> wrote: > This line reads an entire message into memory as a string. Is it > possible that you have a huge email in there (hundreds of MB) with > some attachment encoded as text? No, the largest single message with the mbox is about 100KB large.

Re: MemoryError on reading mbox file

2007-09-12 Thread Christoph Krammer
On 12 Sep., 12:20, David <[EMAIL PROTECTED]> wrote: > It may be that Python's garbage collection isn't keeping up with your app. > > You could try periodically forcing it to run. eg: > > import gc > gc.collect() I tried this, but the problem is not solved. When invoking the garbage collection afte

MemoryError on reading mbox file

2007-09-12 Thread Christoph Krammer
Hello everybody, I have to convert a huge mbox file (~1.5G) to MySQL. I tried with the following simple code: for m in mailbox.mbox(fileName): msg = m.as_string(True) hash = md5.new(msg).hexdigest() try: dbcurs.execute("""INSERT INTO archive (hash, msg) VALUES (%s, %s)""", (hash, ms

Re: re.sub does not replace all occurences

2007-08-07 Thread Christoph Krammer
Neil Cerutti schrieb: > In other words, the fourth argument to sub is count, not a set of > re flags. I knew it had to be something very stupid. Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list

re.sub does not replace all occurences

2007-08-07 Thread Christoph Krammer
Hello everybody, I wanted to use re.sub to strip all HTML tags out of a given string. I learned that there are better ways to do this without the re module, but I would like to know why my code is not working. I use the following: def stripHtml(source): source = re.sub("[\n\r\f]", " ", source)

Read binary data from MySQL database

2007-05-10 Thread Christoph Krammer
Hello, I try to write a python application with wx that shows images from a MySQL database. I use the following code to connect and get data when some event was triggered: dbconn = MySQLdb.connect(host="localhost", user="...", passwd="...", db="images") dbcurs = dbconn.cursor() dbcurs.execute("""

Broken pipe with os.popen3()

2007-04-10 Thread Christoph Krammer
Hello everybody, I try to use an external OCR tool to convert some binary image data to text. The image is in one variable, the text should be converted to another. I use the following code: (si, so, se) = os.popen3('ocrad') si.write(frame) si.close() messagetext += so.read() This code l

How to access multiple group matches?

2007-04-06 Thread Christoph Krammer
Hello, I want to use the re module to split a data stream that consists of several blocks of data. I use the following code: iter = re.finditer('^(HEADER\n.*)+$', data) The data variable contains binary data that has the word HEADER in it in some places and binary data after this word till the n

Re: Using os.popen3() to get binary data

2007-04-06 Thread Christoph Krammer
Just got the solution... After sending the image data with "si.write(image)", I have to close the pipe to tell the program to convert the image with "si.close()". Now everything works fine. Christoph -- http://mail.python.org/mailman/listinfo/python-list

Using os.popen3() to get binary data

2007-04-06 Thread Christoph Krammer
Hello everybody, I need to get the different frames from a GIF image in my python script and want to use the giftopnm program from netpbm to get the frames and directly convert them to pnm files. I tried to use the following code: for image in images: if (image[0:3] == 'GIF'): (si, so,