我正在嘗試運行用Python 2.7.5(不使用Django)編寫的腳本。當它試圖與它拋出以下錯誤MySQLdb.connect()方法連接到遠程MySQL服務器:有沒有辦法在Python 2.7.5中的MySQLdb.connect中將secure_auth設置爲false?
_mysql_exceptions.OperationalError: (2049, "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)")
我已經讀完這個問題:
- Django/MySQL-python - Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)
- mysql error 2049 connection using old (pre-4-1-1) authentication from mac
有沒有辦法在MySQLdb.connect()方法中設置參數來將secure_auth
設置爲false?無需更改任何密碼或從cmd行運行該命令。我看過official docs,那裏面沒有任何東西。
我曾嘗試將secure_auth=False
添加到參數中,但會引發錯誤(如下面的代碼所示)。
的Python:
def get_cursor():
global _cursor
if _cursor is None:
try:
db = MySQLdb.connect(user=_usr, passwd=_pw, host='external.website.com', port=3306, db=_usr, charset="utf8")
# tried this but it doesnt work (as expect but tried anyway) which throws this error
# TypeError: 'secure_auth' is an invalid keyword argument for this function
# db = MySQLdb.connect(user=_usr, passwd=_pw, host='external.website.com', port=3306, db=_usr, charset="utf8", secure_auth=false)
_cursor = db.cursor()
except MySQLdb.OperationalError:
print "error connecting"
raise
return _cursor
上面列出的是我所害怕的。感謝您確認它無法完成。這很有幫助! – tokyovariable 2014-11-20 01:36:29
這確實是由於C API中的一個錯誤:http://bugs.mysql.com/bug.php?id=75425 – niczero 2015-01-06 15:49:25
它看起來像C API已被修補,但問題仍然存在,我使用mysql -python,@niczero你知道爲什麼嗎? – AKFourSeven 2015-01-26 09:08:33