w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
I'm receiving the error 'except MySQLdb.error, e' Syntax Error - invalid syntax when trying to write my scrapy spider to mysql,

You are running your code with Python 3.x, but your code scheme for try.. except section is for Python 2.X.

If you want to run your code with Python 3.x, then change this line:

except MySQLdb.Error, e:


except MySQLdb.Error as e:

And if you want this section of code works with Python 2.x and also Python 3.x, then change it to:

except MySQLdb.Error:
    e = sys.exc_info()[1]

Read more.

But according to your print statement, you write your script for Python 2.x, so it's better to run your code with Python 2.x, instead of Python 3.x

Also this sys.path.append("../python2.7/site-packages") line is strange in first line of your script.

Also your indention of your first code that you pasted was wrong, and i think your are still using that, please use current edited version that is now in your question.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.