Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
socket.timeout: timed out
#1


Hello everyone, I'm a newbie to Python programming and I've really fallen in love with the language; although I've got some little qualms right now.

While reading the book "Violent Python A Cookbook for Hackers, Forensic Analysts, Penetration Testers and Security Engineers", I came across this piece of code:

 import socket
 socket.setdefaulttimeout(2)
s = socket.socket()
 s.connect(("192.168.95.148",21))
 ans = s.recv(1024)
 print ans
When I typed it into the python console on Unix: I got this error message:

Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args) socket.timeout: timed out
So I carried out some research online for a solution or an explanation to what is going on. But I didn't find any that was convincing. For example, I were asked to modify that code to look like this:

import socket

try:
	s = socket.socket()
	s.settimeout(10)
	s.connect((192.168.95.148", 21))
	ans = s.recv(1024)
	print ans
	s.shutdown(1)
	s.close()
	
except socket.error as socketerror:
	print("Error: ", socketerror)
except socket.timeout:
	print("NO RESPONSE")
After running that one, I get this other error message:

Error:
('Error: ', timeout('timed out',))
So, please if anyone could explain what this error messages actually mean and help me understand how I could fix that, I would be very grateful.
Reply


Messages In This Thread
socket.timeout: timed out - by DanielGraham - Dec-22-2017, 02:12 PM
RE: socket.timeout: timed out - by squenson - Dec-22-2017, 03:42 PM
RE: socket.timeout: timed out - by DanielGraham - Dec-22-2017, 06:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to timeout a task using the ThreadpoolExecutor? lowercase00 2 5,150 Feb-07-2023, 05:44 PM
Last Post: deanhystad
  Issues with "connection timed out" duckredbeard 0 2,928 Dec-31-2022, 10:46 PM
Last Post: duckredbeard
  TimeOut a function in a class ? Armandito 1 2,456 Apr-25-2022, 04:51 PM
Last Post: Gribouillis
  FTp timeout except korenron 2 5,289 Feb-01-2022, 06:51 AM
Last Post: korenron
  printing contents of Jar on timeout Rakshan 1 2,267 Jul-30-2021, 07:48 AM
Last Post: buran
  [Selenium]Timed out receiving message from renderer: 10.000 wood_6636 0 3,444 Jun-26-2020, 08:59 AM
Last Post: wood_6636
  Connection timed out error when connecting to SQL server kenwatts275 2 4,145 Jun-02-2020, 07:35 PM
Last Post: bowlofred
  Timed images menator01 0 2,217 Oct-24-2019, 07:34 AM
Last Post: menator01
  FBProphet() Timeout in Anaconda sobrio1 0 3,942 Dec-21-2017, 05:15 AM
Last Post: sobrio1
  timeout value in subprocess jonesin1974 2 7,799 Dec-01-2017, 02:18 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020