Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97057
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-09-23 19:49 -0700 |
| References | <c56e680b-2e04-4fc6-ba57-5ec64459bce9@googlegroups.com> <mtk1sh$ik6$1@ger.gmane.org> <mailman.39.1442760018.21674.python-list@python.org> |
| Message-ID | <e13ed686-94af-444d-a67b-194fe13b0769@googlegroups.com> (permalink) |
| Subject | Re: ConnectionError handling problem |
| From | shiva upreti <katewinslet626@gmail.com> |
On Sunday, September 20, 2015 at 8:11:18 PM UTC+5:30, Laura Creighton wrote:
> 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
Hi
If my script hangs because of the reasons you mentioned above, why doesnt it catch ConnectionError?
My script stops for a while and when I press CTRL+C, it shows ConnectionError without terminating the process, and the script resumes from where it left off.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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