0

我已经完成了搜索,并且对相同错误的现有评论没有帮助

该行:

con = MySQLdb.connect(host = '127.0.0.1', user = 'root', passwd = '', db='vendors', port='3306')

抛出:

Traceback (most recent call last):
  File "mysqlpython.py", line 12, in <module>
    con = MySQLdb.connect(host = '127.0.0.1', user = 'root', passwd = '', db='vendors', port='3306')
  File "/apollo/env/AWSSDKMetrics/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/apollo/env/AWSSDKMetrics/lib/python2.7/site-packages/MySQLdb/connections.py", line 188, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required

对整数的引用是什么?它指的是哪个领域?请记住,我不是 Python 程序员或开发人员。

4

1 回答 1

4

您需要将端口指定为数字,而不是字符串:

con = MySQLdb.connect(
    host='127.0.0.1',
    user='root', passwd='',
    db='vendors', 
    port=3306)

我使用了多行来使上面的示例更具可读性;错误指出 for 的值port必须是整数。

于 2013-03-01T19:44:55.850 回答