top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to raise a socket "104 connection reset by peer error" in Python

0 votes
1,422 views

For testing purposes I want my code to raise a socket "connection reset by peer" error, so that I can test how I handle it, but I am not sure how to raise the error.

posted May 21, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Arbitrary exceptions can be raised with the raise keyword. In Python 3.3, that exact error got its own builtin exception:

http://docs.python.org/3.3/tutorial/errors.html#raising-exceptions
http://docs.python.org/3.3/library/exceptions.html#ConnectionResetError

In earlier versions of Python, you will have to raise OSError and set its errno attribute.

answer May 21, 2013 by anonymous
Similar Questions
0 votes

I have a simple housekeeping session that deletes data prior to one month from teradata tables.This is done using SQL transformation.The mapping has logic such that it handles 3 types of files (daily , monthly first week ,monthly -last week).logic for all 3 types is same.Deleting data prior to 1 month.Router is used to handle this.

The session executes properly for low volume of data(daily file) but when the table has higher volume of data in production , it gives below error :

TRANSF_1_1_1> pmsql_50065 [ERROR] ODL error: FnName: Close -- [Teradata][Unix system error] Socket error - Connection reset by peer FnName: Execute Direct -- [Teradata][Unix system error] 104 Socket error - Connection reset by peer ODBC call to SQLError failed. . TRANSF_1_1_1> CMN_1761 Timestamp Event: [Fri Aug 08 09:45:01 2014]

We have tried re-executing the session but no luck. Weird part is the delete command is being executed in database as we could see data deleted as required but the session is failing.

Please let me know what is the issue here and also the solution.Thank you.

+2 votes

As per my understanding Receive system calls will be a blocking call of the code... it will not go ahead unless it receives the response from client .. my question is how would i set time in that? i want my code should wait only for few seconds then it has to come out from that

+2 votes

The problem description:

There are set of processes running on my system say process_set_1. Build a process agent which runs an asynchronous socket listening to incoming requests from process_set_1. Each process sends an id. The agent stores these ids in a dictionary and sends response that ur id has been accepted. Now agent process receives some data from another process (which is some sort of sister process for the agent). This data contains id along with a command which is to be sent by the agent to the process_set_1 through HTTP client over AF_UNIX socket, since each process in process_set_1 has a HTTP listening CLI. The process agent sends an HTTP request by recognizing id stored in dictionary to the process_set_1. A service running in the process_set_1 routes this HTTP command to the respective process.

Now my problem is the HTTP request which to be sent must go through AF_UNIX socket. I got this solution.

class UnixStreamHTTPConnection(httplib.HTTPConnection):

    def __init__(self, path, host='localhost/rg_cli',port=None, strict=None,
                 timeout=None):
        httplib.HTTPConnection.__init__(self, host, port=port, strict=strict,
                                        timeout=timeout)
        self.path=path

    def connect(self):
        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        self.sock.connect(self.path)

But this cannot work since normal socket will not work and thus i thought of asyncore module in python. To use asyncore module again i will have to subclass asyncore.dispatcher. This class also contains connect() method.

Another problem is I don't know how asyncore module works and thus not able to find a way to mix the work of 1) listening forever, accept the connection, store id and the sock_fd.
2) accept data from the process' agent sister process, retrieve the sock_fd by matching the id in the dictionary and send it through the AF_UNIX socket.

Please help since i have already spent 2 days digging it out. Sorry if could explain my problem very well.

+1 vote

In Socket-Programming, I want to send whole ".txt" file from server to client. is it possible?

+2 votes

I have function in python,(Assume that i have imported all necessary module),

 def DL_Iperf(args):
        ssh=paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(server_ip,username="root",password=Password)
some_code

This function is actually a thread and it will be created as many no of UE i have, (Ex: if i have 1 UE than 1 Thread will be created),

So, if i have 1 UE/ 2 UE than its working but if i have 3 UE then it is failing, with error "Paramiko : Error reading SSH protocol banner",

Below is the stderr of the script,

    No handlers could be found for logger "paramiko.transport"

    Unhandled exception in thread started by <function DL_Iperf at 0x02B8ACF0>
    Traceback (most recent call last):

    File "C:\Users\qxdm-5\Desktop\Chirag\LTE_11_Perfect_Working\TCP_Latest_2\Windo
    ws_UE\slave.py", line 379, in DL_Iperf

    ssh.connect(ServerIp,username="root",password=Pwd)

    File "build\bdist.win32\egg\paramiko\client.py", line 295, in connect

    File "build\bdist.win32\egg\paramiko\transport.py", line 451, in start_client

paramiko.SSHException: Error reading SSH protocol banner

From some reference i found that this is because of some network related issue, but my question is if it network related then why everytime in 3rd call of the function i am getting this error? And how do i resolve it?

...