Menu

Unable to use 'port' in MySQLdb.connect

Help
Peter Nye
2003-04-01
2012-09-19
  • Peter Nye

    Peter Nye - 2003-04-01

    When the 'port' argument is set in call to MySQLdb.connect() this exception is shown(shortened):
    File "E:\Python22\Lib\site-packages\MySQLdb\connections.py", line 41, in _make_connection
        apply(super(ConnectionBase, self).__init__, args, kwargs)
    TypeError: connect() argument 2 must be string, not int

    If the number is changed to a string the exception reads:
    (shortened)
    File "E:\Python22\Lib\site-packages\MySQLdb\connections.py", line 41, in _make_connection
        apply(super(ConnectionBase, self).__init__, args, kwargs)
    TypeError: an integer is required

    Solution?

     
    • Greg Fortune

      Greg Fortune - 2003-04-06

      It would be helpful to see the entire call you are making to connect as well as the types and values of each argument to the call...

      Greg

       
      • Peter Nye

        Peter Nye - 2003-04-07

        Here is the code for the call:
        try:
                    conn = MySQLdb.connect( self._dbConnInfo.host,
                                            self._dbConnInfo.port,
                                            self._dbConnInfo.user,
                                            self._dbConnInfo.password,
                                            self._dbConnInfo.db )
                except MySQLdb.Error, e:
                    print "Error %d: %s" % (e.args[0], e.args[1])
                    sys.exit(1)

        I have also used values directly, both string and int, and also have tried to coerce values using str() and int().

        Thanks for looking at this.

         
        • Greg Fortune

          Greg Fortune - 2003-04-07

          You'll need to use named parameters.

          MySQLdb.connect(user=username,passwd=password,db=database,host=hostname,port=req_port)

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.