Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96879

Re: ConnectionError handling problem

From Laura Creighton <lac@openend.se>
Subject Re: ConnectionError handling problem
References <c56e680b-2e04-4fc6-ba57-5ec64459bce9@googlegroups.com> <mtk1sh$ik6$1@ger.gmane.org>
Date 2015-09-20 16:40 +0200
Newsgroups comp.lang.python
Message-ID <mailman.39.1442760018.21674.python-list@python.org> (permalink)

Show all headers | View raw


The discussion about why or why not to use a bare except has gotten us
away from the problem reported, which is "why is my script hanging?"

In a message of Sat, 19 Sep 2015 17:18:12 +0100, Mark Lawrence writes:
>> I am learning python. I wrote a script using requests module.
>> The scripts runs fine for sometime, but after a while it hangs. When I press CTRL+C it shows ConnectionError even though I have included exception handling.
>> I am not sure as to why it cant handle ConnectionError when the script runs for a long time.
>>
>> This is a part(causing issues) of the script I am running:
>>
>> while(k<46656):
>> 		j=res[k]
>> 		url="http://172.16.68.6:8090/login.xml"	
>> 		query_args = {'mode':'191', 'username':str(i), 'password':str(j), 'a':'1442397582010', 'producttype':'0'}
>> 		
>> 		try:
>> 			r=requests.post(url, data=query_args)
>> 		except:
>> 			print "Connection error"
>> 			time.sleep(30)
>> 			continue
>>
>> 		html=r.text
>> 		if(len(html) < 10):
>> 			continue
>>
>> 		if("The system could not log you on" not in html):
>> 			print "hello"
>> 			filehandle=open("ids", "a")
>> 			filehandle.write(str(i)+'\n')
>> 			filehandle.write(str(j)+'\n')
>> 			filehandle.close()
>> 			break
>> 		
>> 		k=k+1
>>
>> Any help will be highly appreciated.

So, when it hangs there are two main problems you can have.  One sort
is that the other side, http://172.16.68.6:8090/ it in itself
configured to only let people use a connection for a certain amount of
time.  If you are using it for longer, it will disconnect you.  Or the
other sort is that the other side disconnects people who have been
silent for a certain amount of time.  If you haven't send anything for
a certain amount of time it will log you off.  There are lots of other
things that work this way -- the system may see many attempts to login
and think you are trying to break into the system, the machine may
have crashed ... but the bottom line is that the reason your script
hangs is that there is nobody there on the other end.

The other sort of problem you can have is that the other end is
alive and well and talking to you, but you don't understand what
you are getting, and you are ignoring things you don't understand.
This can look exactly the same.

To find out what is going on you need to log what it is that you
are getting, to see if the answer is 'nothing' or 'garbage'.

Laura

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-18 23:13 -0700
  Re: ConnectionError handling problem Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-19 17:18 +0100
    Re: ConnectionError handling problem Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-09-20 12:45 +0000
      Re: ConnectionError handling problem Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-20 14:13 +0100
        Re: ConnectionError handling problem Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-09-20 13:28 +0000
      Re: ConnectionError handling problem Chris Angelico <rosuav@gmail.com> - 2015-09-20 23:25 +1000
        Re: ConnectionError handling problem Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-09-20 13:33 +0000
  Re: ConnectionError handling problem Laura Creighton <lac@openend.se> - 2015-09-20 16:40 +0200
    Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-23 19:49 -0700
      Re: ConnectionError handling problem Laura Creighton <lac@openend.se> - 2015-09-24 12:38 +0200
        Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 20:52 -0700
        Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 22:41 -0700
        Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 22:42 -0700

csiph-web