Python socket.error: [Errno 61] Connection refused

10,228

It looks like there is nothing running on the host and port you specified (you can check it with nmap, for example).

In the case it does, is it expecting to receive anything and responding to it?

EDIT: your code is not working because in the remote host and the port you specified (8080), there must be some some code running, listening for messages and responding to them. If there is nothing running on that port, it obviously returns you the "Connection refused" error.

In other words, you created the client, but not the server :P

Share:
10,228

Related videos on Youtube

resident
Author by

resident

Updated on September 15, 2022

Comments

  • resident
    resident over 1 year

    I am very new to socket programming. I am trying to connect to a power supply over ethernet. My Mac (OS X) is connected to an ethernet switch and the power supply is also connected to the switch. I have some code written in python to send/receive commands/messages to/from the power supply.

    The switch interface allows me to assign a static IP to the supply. It is this same IP that I use as the target IP in the following code:

        def __init__( self, IP_TARGET ):
            IP = IP_TARGET
            PORT = 8080
            self.supply = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
            self.supply.connect( (IP, PORT) )
    

    This code runs without any issues. My next goal is communicate with the device using the following code:

        def getDeviceInfo( self ):
            self.supply.send('some command ')
            self.supply.recv(10)
    

    Using some print statements I have narrowed the issue down to the recv() command. The send() throws no errors. I get the following error

    ...in getDeviceInfo
    self.supply.recv(10) socket.error: [Errno 61] Connection refused
    

    I am able to ping the device using the IP that I assigned it using the ethernet switch. I have firewall off. I have searched the www for clues as to how I might resolve this error, but to no avail. Any thoughts?

    • resident
      resident over 8 years
      The supply is using a Digi connect ME ethernet port. Part number = DC-ME-01T-S
  • resident
    resident over 8 years
    The supply shows up in switch's interface. The port I chose was random (I thought anything above 4096 would be okay). I will have to learn about nmap before I use it. But to answer the last question, I am not sure that its expecting to receive. I was expecting that by sending it a command that I would simply get a response (clearly I am having wishful thoughts).
  • rarguelloF
    rarguelloF over 8 years
    I edited my answer, I hope I explained myself better :D