类型错误:需要一个整数 [英] TypeError: an integer is required

查看:24
本文介绍了类型错误:需要一个整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了搜索,但对同一错误的现有评论没有帮助

I have done the search and the existing comments on same error was not helpful

行:

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 程序员或开发人员.

What is the reference to the integer? Which field is it referring to? Keep in mind that I am not a python programmer or developer.

推荐答案

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

You need to specify the port as a number, not a string:

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

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

I used multiple lines to make the above example more readable; the error points out that the value for port must be an integer.

这篇关于类型错误:需要一个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆