TypeError: iterable argument required

eryksun () eryksun at gmail.com
Mon Apr 4 22:49:12 EDT 2011


On Monday, April 4, 2011 9:40:33 AM UTC-4, Νικόλαος Κούρας wrote:

In one of your messages you wrote the following:

> cursor.execute( '''INSERT INTO users(mail, comment) VALUES(%s,
> %s)''', (mail, comment) )
> except MySQLdb.Error:
> print ( "Error %d: %s" % (e.args[0], e.args[1]) )

Is this a typo in your message or the actual code? If 'e' is unassigned you should be getting a NameError. The standard Python2 syntax (before version 2.6) is the following:

    except MySQLdb.Error, e:
        print("Error %d: %s" % (e.args[0], e.args[1]))

You also wrote:

> mail = None, comment = None

This should cause a SyntaxError because it's trying to assign None = None. That's assuming it's on line 167, after the cursor.execute(...) on line 166.

> Whats was the problem as i have written it?
> Your solution is the same as mine except the fact that you assign
> values and statements into variables.

I was just rewriting it to make sure I was parsing it right.

> I tried it but iam getting an Internal Server Error.

Yes, I made a mistake. It should have been `cursor.execute(SQL_COMMENT_FORM, (mail, comment))`, using a comma instead of a '%' to have it generate SQL string literals from the tuple.

> Also i noticed that if i append a query string in the end of a url
> with the varibble mail attached like
> 
> http://superhost.gr/hosting.html?mail=test
> 
> then page hosting.html does load without any problem.
> 
> If i remove the query string from the ned of the URL then i'am getting
> the error message i posted.
> 
> So its not that the if condition is wrong but something happens with
> the form variable 'mail' .....

Insert a test to print out the type and value of 'mail' for various inputs. 

Regarding the message itself, on Python 2.7.1, I get the following TypeError message if I try iterate None:

    TypeError: argument of type 'NoneType' is not iterable

Python 2.5.2 on "http://shell.appspot.com" yields the same error. Version 2.5 improved the error messages to include the type of the object (see issue 1507676). The message "iterable argument required" looks like an older version of CPython.



More information about the Python-list mailing list