I have a standalone PyQGIS program which generates warnings as follows:

Warning 1: Value val of field field_name of feature n not successfully written. Possibly due to too larger number with respect to field width

I want to suppress these warnings to be able to see future errors since I have more than 1000 features and any warning/errors after the 1000th will not be displayed. Any idea how to do this?

  • Have you found solution? I have same problem.
    – Goran
    Apr 24, 2018 at 12:10
  • @GoranGrle: No, I have not. I've ditched PyQGIS in favour of Shapely + Fiona. Apr 24, 2018 at 12:50

2 Answers 2


I have not tested this but you may be able to use QgsMessageLog.instance().messageReceived.connect() event to catch python warnings, see this q/a:

Catching WMS error message from log messages panel in QGIS with python?

If your writing out the warnings I would just add a counter, if counter < 1000 keep showing warnings otherwise stop showing them:

counter = 0
# check for some warning condition
if warning:
    if counter < 1000:
        print 'Value val of field field_name of feature n not successfully written. Possibly due to too larger number with respect to field width'
  • No, I'm not writing out the warnings myself, or this question would be pretty pointless. It's PyQGIS's default warning. Apr 24, 2018 at 12:48

In case anyone is still looking for a way to do this: (the author of this post mentioned above that now is using Shapely and Fiona).

I found different ways to avoid the warning messages mentioned in this post:

  1. Fix the warning: if the warning mentions that a feature's field could not be written because of trying to write a number larger than the maximum width of the field, use your preferred GIS software to cut the number field by either creating another field with the same number but rounded up/down. This works in case you have a value with a large number of significant figures but they are actually not important.

  2. If 1 would not work for you, run your pyqgis .py script through a .sh script and direct all warning and error messages to a log (or null in case you don't even want to have these messages). For example, I have the following .sh script:

    while read line;
                echo $oid
                python create_input_data.py --oid $oid
            done < "/Users/list.txt

where create_input_data.py is the PyQGIS script that is printing the warnings. When you run the .sh in the terminal, add the "> error.log 2>&1" after the name of the .sh script to create a text file that includes all lines that would have been printed otherwise at the terminal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.