close

[Solved] _csv.Error: field larger than field limit (131072)

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error _csv.Error: field larger than field limit (131072) in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How _csv.Error: field larger than field limit (131072) Error Occurs?

Today I get the following error _csv.Error: field larger than field limit (131072) in python.

How To Solve _csv.Error: field larger than field limit (131072) Error ?

  1. How To Solve _csv.Error: field larger than field limit (131072) Error ?

    To Solve _csv.Error: field larger than field limit (131072) Error sys.maxsize works for Python 2.x and 3.x. sys.maxint would only work with Python 2.x (SO: what-is-sys-maxint-in-python-3)

  2. _csv.Error: field larger than field limit (131072)

    To Solve _csv.Error: field larger than field limit (131072) Error sys.maxsize works for Python 2.x and 3.x. sys.maxint would only work with Python 2.x (SO: what-is-sys-maxint-in-python-3)

Solution 1

The csv file might contain very huge fields, therefore increase the field_size_limit:

import sys
import csv

csv.field_size_limit(sys.maxsize)

sys.maxsize works for Python 2.x and 3.x. sys.maxint would only work with Python 2.x (SO: what-is-sys-maxint-in-python-3)

Update

As Geoff pointed out, the code above might result in the following error: OverflowError: Python int too large to convert to C long. To circumvent this, you could use the following quick and dirty code (which should work on every system with Python 2 and Python 3):

import sys
import csv
maxInt = sys.maxsize

while True:
    # decrease the maxInt value by factor 10 
    # as long as the OverflowError occurs.

    try:
        csv.field_size_limit(maxInt)
        break
    except OverflowError:

Solution 2

This could be because your CSV file has embedded single or double quotes. If your CSV file is tab-delimited try opening it as:

c = csv.reader(f, delimiter='\t', quoting=csv.QUOTE_NONE)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read