Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96856
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: ConnectionError handling problem |
| Date | 2015-09-19 17:18 +0100 |
| References | <c56e680b-2e04-4fc6-ba57-5ec64459bce9@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.24.1442679607.21674.python-list@python.org> (permalink) |
On 19/09/2015 07:13, shiva upreti wrote:
> 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.
>
Never use a bare except in Python, always handle the bare minimum number
of exceptions that you need to, in this case your ConnectionError.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
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