This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: csv.reader endless loop
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: andrewmcnamara Nosy List: ajaksu2, andrewmcnamara, georg.brandl, ironfroggy, krumms, wwwingman
Priority: normal Keywords:

Created on 2005-12-15 11:04 by wwwingman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (8)
msg27074 - (view) Author: Christian Harms (wwwingman) Date: 2005-12-15 11:04
Hi, 

the csv.reader produce a endless loop, ifan parsing
Error is in the last line of the CSV-File. If you put
an "\r" in the last line, cvs.Error is raised and
StopIteration will lost.

import csv, StringIO
fp = StringIO.StringIO("line1\nline2\rerror")
reader = csv.reader(fp)

while 1:
    try: 
        print reader.next()
    except csv.Error:
        print "Error"
    except StopIteration:
        break

Die Problem is in python 2.3 AND python 2.4. Other
version are not checked.
msg27075 - (view) Author: Thomas Lee (krumms) (Python committer) Date: 2005-12-17 15:17
Logged In: YES 
user_id=315535

I think this may be fixed in subversion:

tom@vanilla:~/work/python$ svn info
Path: .
URL: http://svn.python.org/projects/python/trunk
Repository UUID: 6015fed2-1504-0410-9fe1-9d1591cc4771
Revision: 41731
Node Kind: directory
Schedule: normal
Last Changed Author: fredrik.lundh
Last Changed Rev: 41729
Last Changed Date: 2005-12-17 18:33:21 +1000 (Sat, 17 Dec 2005)
Properties Last Updated: 2005-12-17 21:44:46 +1000 (Sat, 17
Dec 2005)

tom@vanilla:~/work/python$ python -V
Python 2.4.2
tom@vanilla:~/work/python$ python Sandbox/csv_reader_test.py
['line1']
ERROR: newline inside string
tom@vanilla:~/work/python$ ./python -V
Python 2.5a0
tom@vanilla:~/work/python$ ./python Sandbox/csv_reader_test.py
['line1']
ERROR: new-line character seen in unquoted field - do you
need to open the file in universal-newline mode?

msg27076 - (view) Author: Thomas Lee (krumms) (Python committer) Date: 2005-12-17 16:56
Logged In: YES 
user_id=315535

Actually, the problem may not be a problem with the csv
module at all, it may be a misinterpretation of the API on
the submitters part.


Is there any time a non-fatal csv.Error would/could be
raised? Seems to me that a csv.Error would imply a
StopIteration/break ...
msg27077 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-12-17 17:02
Logged In: YES 
user_id=1188172

Let the expert judge.
msg27078 - (view) Author: Christian Harms (wwwingman) Date: 2006-01-03 08:56
Logged In: YES 
user_id=1405594

>birkenfeld: csv.Error would imply a StopIteration/break ...

No, this Error says only: "Can not parse THIS line ...".
This exception is used for reading buggy
outlook-Export-CSV-Files und trying to read some lines (not
all). And if the error is in the last line, the
StopIteration will be forgotten and the Error will be
produced in a endless-loop.

input = StringIO.StringIO("1.\rerror\n2.ok\n3.\rerr")
#insert my while-loop

#Output:
>Error
>2.ok
>Error
>Error
...
msg27079 - (view) Author: Calvin Spealman (ironfroggy) Date: 2007-01-13 06:48
How do you expect it to handle this? Should it treat \r bytes as a newline or as content of the field?
msg81569 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-10 18:10
Invalid per discussion.
msg81684 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-11 22:54
Confirmed as working on trunk and py3k.
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42696
2009-02-11 22:54:02ajaksu2setstatus: open -> closed
resolution: out of date
messages: + msg81684
2009-02-10 18:10:40ajaksu2setnosy: + ajaksu2
messages: + msg81569
title: csv.reader endless loop -> csv.reader endless loop
2005-12-15 11:04:26wwwingmancreate