Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'from:addr:yahoo.co.uk': 0.05; 'except:': 0.07; 'scripts': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python.': 0.11; 'exception': 0.13; '"a")': 0.16; '"connection': 0.16; 'ctrl+c': 0.16; 'error"': 0.16; 'handling.': 0.16; 'hangs.': 0.16; 'issues)': 0.16; 'on"': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'running:': 0.16; 'subject:handling': 0.16; 'url=""': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'runs': 0.18; 'language': 0.19; 'exceptions': 0.22; 'lawrence': 0.22; 'subject:problem': 0.22; 'wrote': 0.23; 'header :In-Reply-To:1': 0.24; 'requests': 0.25; 'script': 0.25; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'appreciated.': 0.27; 'module.': 0.27; "skip:' 10": 0.28; 'fine': 0.28; 'print': 0.30; 'included': 0.32; 'language.': 0.32; "skip:' 20": 0.34; 'except': 0.34; 'handle': 0.34; 'could': 0.35; 'but': 0.36; 'skip:{ 10': 0.36; 'url:non-standard http port': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'minimum': 0.38; 'log': 0.38; 'why': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'your': 0.60; 'press': 0.61; 'charset:windows-1252': 0.62; 'to,': 0.63; 'our': 0.64; 'url:6': 0.66; 'pythonistas,': 0.84; 'url:172': 0.84; 'url:16': 0.95; 'url:login': 0.96 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: ConnectionError handling problem Date: Sat, 19 Sep 2015 17:18:12 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 195.147.66.69 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442679607 news.xs4all.nl 23858 [2001:888:2000:d::a6]:57295 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96856 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