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


Groups > comp.lang.python > #96879

Re: ConnectionError handling problem

Path csiph.com!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <lac@openend.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'except:': 0.07; 'scripts': 0.09; 'disconnect': 0.09; 'ignoring': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'python.': 0.11; 'exception': 0.13; '"a")': 0.16; '"connection': 0.16; 'crashed': 0.16; 'ctrl+c': 0.16; 'error"': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'getting,': 0.16; 'handling.': 0.16; 'hangs': 0.16; 'hangs.': 0.16; 'issues)': 0.16; 'message-id:@fido.openend.se': 0.16; 'on"': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'running:': 0.16; 'subject:handling': 0.16; 'url=""': 0.16; 'laura': 0.18; 'try:': 0.18; 'runs': 0.18; '2015': 0.20; 'machine': 0.21; 'lawrence': 0.22; 'sep': 0.22; 'subject:problem': 0.22; 'trying': 0.22; 'wrote': 0.23; 'sat,': 0.23; "haven't": 0.24; 'discussion': 0.24; 'requests': 0.25; 'sort': 0.25; 'script': 0.25; 'appreciated.': 0.27; 'module.': 0.27; "skip:' 10": 0.28; 'fine': 0.28; 'received:se': 0.29; 'print': 0.30; 'connection': 0.30; 'system,': 0.30; 'certain': 0.31; 'included': 0.32; 'problem': 0.33; "skip:' 20": 0.34; 'except': 0.34; 'handle': 0.34; 'so,': 0.35; 'could': 0.35; 'configured': 0.35; 'but': 0.36; 'there': 0.36; 'skip:{ 10': 0.36; 'url:non-standard http port': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'itself': 0.38; 'anything': 0.38; 'log': 0.38; 'end': 0.39; 'why': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'your': 0.60; 'press': 0.61; 'header:Message-Id:1': 0.61; 'side': 0.62; 'you.': 0.64; 'url:6': 0.66; 'talking': 0.67; 'gotten': 0.76; 'header:In-reply-to:1': 0.84; 'url:172': 0.84; 'have.': 0.93; 'url:16': 0.95; 'silent': 0.96; 'url:login': 0.96
To python-list@python.org
From Laura Creighton <lac@openend.se>
Subject Re: ConnectionError handling problem
In-reply-to <mtk1sh$ik6$1@ger.gmane.org>
References <c56e680b-2e04-4fc6-ba57-5ec64459bce9@googlegroups.com> <mtk1sh$ik6$1@ger.gmane.org>
Comments In-reply-to Mark Lawrence <breamoreboy@yahoo.co.uk> message dated "Sat, 19 Sep 2015 17:18:12 +0100."
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-ID <16024.1442760012.1@fido>
Content-Transfer-Encoding quoted-printable
Date Sun, 20 Sep 2015 16:40:13 +0200
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [82.96.5.2]); Sun, 20 Sep 2015 16:40:14 +0200 (CEST)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.39.1442760018.21674.python-list@python.org> (permalink)
Lines 66
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442760018 news.xs4all.nl 23862 [2001:888:2000:d::a6]:57610
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96879

Show key headers only | 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