0
votes

I'm sending a simple 'post' request through the 'requests' module. It works fine when execute it directly through the linux terminal. However, when I set it up through the crontab, the log is indicating and error.

  • If I execute the below through the terminal, it works fine.

'/usr/bin/python3.6 /location/sa/tb/uc/md/se/sea.py'

  • If I setup the crontab as follows, I get an error.
          • /usr/bin/python3.6 /location/sa/tb/uc/md/se/sea.py >> ~/Test_log.log 2>&1
  • Below is the error message:

File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in validate_conn conn.connect() File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 344, in connect ssl_context=context) File "/usr/local/lib/python3.6/site-packages/urllib3/util/ssl.py", line 345, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "/usr/lib64/python3.6/ssl.py", line 365, in wrap_socket _context=self, _session=session) File "/usr/lib64/python3.6/ssl.py", line 776, in init self.do_handshake() File "/usr/lib64/python3.6/ssl.py", line 1036, in do_handshake self._sslobj.do_handshake() File "/usr/lib64/python3.6/ssl.py", line 648, in do_handshake self._sslobj.do_handshake() ConnectionResetError: [Errno 104] Connection reset by peer

What did I try?

  • Tried adding absolute path inside the script.

  • Added a proxy to the headers, but no go.

Any help would be appreciated.

1
For first time execution, the error given is [Errno 104] Connection reset by peer. Is further request errors are [Errno 32] Broken pipe?Jishan Shaikh
The further error is: urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))Venkat

1 Answers

0
votes

Some servers don't start re-listen immediately (check_mk flag), while calling multiple requests from a single connection. One of the reason is to avoid DoS attacks and service availability to all users.

Since your crontab made your script to call the same API multiple times using a single connection, I'd suggest you to add a void timer before making a request, e.g. add time.sleep(0.01) just before calling the API.