Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:15:38+00:00 2026-06-10T18:15:38+00:00

I keep getting an error while running a relatively simple TCP client. The troublesome

  • 0

I keep getting an error while running a relatively simple TCP client. The troublesome line is the call to socket.connect(..) which looks to through a TypeError. Any ideas why? I’ve put in hard coded values for now for host and port for now.

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 846, in emit
    msg = self.format(record)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 723, in format
    return fmt.format(record)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 464, in format
    record.message = record.getMessage()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 328, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Logged from file run_42bets.py, line 70

# ------

#!/usr/bin/python

import importlib
import logging
import optparse
import os
import socket

SCRIPT_NAME = os.path.basename(__file__)
VERSION = SCRIPT_NAME + ' 1.0'

class TCPCommandSender:
    """Wrapper around TCP client for sending commands"""
    def __init__(self, host, port):
        """Setup connection to host:port"""
        logging.info("Connecting to server %s:%s", host, port)

        self.__host = host
        self.__port = port

        self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.__socket.connect(("127.0.0.1", 2000))

    def __enter__(self):
        """Return TCPCommandSender instance"""
        return TCPCommandSender

    def __exit__(self, type, value, traceback):
        """Tear down connection if connected"""
        if self.__socket:
           logging.info("Disconnecting from server %s:%s", self.__host, self.__port)
           self.__socket.close()

    def send(self, cmd):
        """Send admin command to server and return received message"""
        try:
            self.__socket.sendall(cmd)
            return self.__socket.recv(1024)
        except socket.error, msg:
            logging.critical("Failed to send admin cmd; reason=%s", msg)
            return "ERROR"

def main():
    #customise logging
    logging.basicConfig(filename=SCRIPT_NAME + '.log', 
                        filemode='a',
                        format='%(asctime)s %(levelname)s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        level=logging.INFO) 

    logging.info("Starting %s", SCRIPT_NAME)

    #define command line arguments
    parser = optparse.OptionParser("Usage: %prog [options]", version=VERSION)
    parser.add_option('--host', dest='host', help='Server to send commands to', type='string')
    parser.add_option('--port', dest='port', help='Server admin port to send commands to', type='int')
    parser.add_option('--config', dest='config', help='Python configuration module to configure algo', metavar='FILE')
    (options, args) = parser.parse_args()

    #check we have all required command line arguments
    if options.host and options.port and options.config:
        try:
            with TCPCommandSender(options.host, options.port) as cmd_sender:
                try:
                    logging.info("Running configuration module %s", options.config)
                    logging.info("Finished configuration module %s", options.config)
                except:
                    logging.critical("Error while running configuration module %s", options.config)
        except EnvironmentError, msg:
            logging.critical("Failed to connect to server %s:%s", options.host, options.port, msg)
    else:
        parser.error("Incorrect number/set of arguments provided, see --help")  

    logging.info("Ending %s", SCRIPT_NAME)

if __name__ == "__main__":
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:15:39+00:00Added an answer on June 10, 2026 at 6:15 pm

    Your problem is this line:

    logging.critical("Failed to connect to server %s:%s", options.host, options.port, msg)
    

    Python is complaining that you gave it three things to put into the string (options.host, options.port, and msg), but you only gave it two places to put them (only two %s).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error: Uncaught Syntax Error: Unexpected Token ILLEGAL while running Ext
So while running this code I keep getting the error: /Applications/TextMate.app/Contents/SharedSupport/Bundles/C.tmbundle/Support/bin/bootstrap.sh: line 7: 11441
I keep getting this error while trying to modify some tables. Here's my code:
While trying to host the CLR, I keep getting this: error C2440: 'function' :
I keep getting the dreaded java.something.someException errors while running my java app. and I
I keep getting these errors: Error running 'make ', please read /Users/jason* /.rvm/log/ruby-1.9.2-p320/make.log There
While trying to git push heroku master, I keep getting the error : Counting
I keep on getting this error when running one of my scripts; PHP Fatal
Keep getting this error while implementing billing. What is going on? 01-30 22:33:31.600: E/Finsky(25902):
I keep getting this error while setting up ehcache in Spring MVC. org.springframework.beans.factory.BeanCreationException: Error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.