Path: csiph.com!goblin2!goblin.stu.neva.ru!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; 'else:': 0.03; 'kind,': 0.05; ':-(': 0.07; 'clause': 0.07; 'encouraging': 0.07; 'except:': 0.07; 'friday,': 0.07; 'cc:addr:python-list': 0.09; 'statements': 0.09; 'that).': 0.09; 'python': 0.10; 'english.': 0.13; 'exception': 0.13; '"connection': 0.16; '-rn': 0.16; 'call?': 0.16; 'command,': 0.16; 'command:': 0.16; 'error"': 0.16; 'exceptions.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'hangs': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'nonexistent': 0.16; 'presume': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'reraised.': 0.16; 'simpson': 0.16; 'status.': 0.16; 'subject:handling': 0.16; 'wrote:': 0.16; 'laura': 0.18; 'try:': 0.18; 'shell': 0.18; 'language': 0.19; '>>>': 0.20; '2015': 0.20; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; 'ok.': 0.22; 'subject:problem': 0.22; 'cheers,': 0.22; 'pass': 0.22; 'cc:no real name:2**0': 0.22; 'bit': 0.23; '(or': 0.23; 'this:': 0.23; 'second': 0.24; 'cc:addr:gmail.com': 0.24; 'unix': 0.24; 'header :In-Reply-To:1': 0.24; 'hosting': 0.25; 'header:User-Agent:1': 0.26; 'figure': 0.27; 'looks': 0.29; 'issuing': 0.29; 'prints': 0.29; 'raise': 0.29; 'print': 0.30; 'connection': 0.30; "we're": 0.30; 'code': 0.30; 'connections': 0.30; 'normally': 0.30; 'probably': 0.31; 'possibly': 0.32; 'maybe': 0.33; 'run': 0.33; 'problem': 0.33; 'adjust': 0.33; 'call,': 0.33; 'raising': 0.33; 'received:com.au': 0.33; 'open': 0.33; "i'll": 0.33; 'correctly': 0.34; 'except': 0.34; 'handle': 0.34; 'server': 0.34; 'that,': 0.34; 'skip:* 20': 0.35; 'quite': 0.35; 'problem.': 0.35; 'should': 0.36; 'there': 0.36; 'url:non-standard http port': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'charset:us-ascii': 0.37; 'doing': 0.38; 'skip:p 20': 0.38; 'someone': 0.38; 'thank': 0.38; 'files': 0.38; 'why': 0.39; 'does': 0.39; 'where': 0.40; 'some': 0.40; 'him': 0.60; 'your': 0.60; 'press': 0.61; 'show': 0.62; 'us.': 0.62; 'more': 0.63; 'cameron': 0.66; 'elsewhere': 0.66; 'nombre': 0.66; 'url:6': 0.66; 'directly.': 0.76; 'hanging': 0.84; 'me).': 0.84; 'presumably': 0.84; 'url:172': 0.84; 'utc+5:30,': 0.84; 'examine': 0.95; 'url:16': 0.95; 'url:login': 0.96 Date: Sun, 27 Sep 2015 07:43:24 +1000 From: Cameron Simpson To: Gonzalo V Cc: shiva upreti , python-list@python.org Subject: Re: ConnectionError handling problem MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) References: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=W4DFLkik c=1 sm=1 tr=0 a=t6IGaf1l19PsElHJfDn/BA==:117 a=t6IGaf1l19PsElHJfDn/BA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=vrnE16BAAAAA:8 a=kj9zAlcOel0A:10 a=ff-B7xzCdYMA:10 a=pGLkceISAAAA:8 a=nP5_cENUAAAA:8 a=frEERq_XMvNfNjLBHH0A:9 a=CjuIK1q_8ugA:10 a=ldJ9EG8W3yUA:10 a=qiWi7Edwir4A:10 a=NWVoK91CQyQA:10 a=e_9gCKMlLccA:10 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: 107 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443305465 news.xs4all.nl 23756 [2001:888:2000:d::a6]:44717 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97145 On 26Sep2015 09:46, Gonzalo V wrote: >Hi Cameron. >i had the same problems and you have to tell to python what to do with the >connect problem. Definitely. That's why we're encouraging him to handle specific exceptions. >try this: >... >except *urllib.error.HTTPError* as e: > if e.getcode()==504: > disp = "SIN RESPUESTA DEL SERVIDOR" #(No answer from the >server) > nombre='' > origen='' > > precioAhora='' > print(e.getcode(),disp) > pass You're aware that the "pass" there does nothing? Perhaps you're considering "continue"? Normally when I write a specific clause like that it looks a bit like this: try this: ... except *urllib.error.HTTPError* as e: if e.getcode()==504: warning("about 504 error...") nombre = '' else: raise This arranges that for _other_ HTTPErrors which I do not correctly handle that the exception is reraised. >greeting from Chile. Sorry my english. Don't apologise. Thank you for working in a second language to accomodate us. I apologise for my Spanish, which is nonexistent :-( Cheers, Cameron Simpson >Saludos, >Gonzalo > >2015-09-25 3:24 GMT-04:00 Cameron Simpson : > >> On 24Sep2015 22:46, shiva upreti wrote: >> >>> On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson >>> wrote: >>> >>>> On 24Sep2015 20:57, shiva upreti wrote: >>>> >Thank you Cameron. >>>> >I think the problem with my code is that it just hangs without raising >>>> any >exceptions. And as mentioned by Laura above that when I press CTRL+C, >>>> it >just catches that exception and prints ConnectionError which is >>>> definitely >a lie in this case as you mentioned. >>>> >>> >> Ok. You original code says: >> >> try: >> r=requests.post(url, data=query_args) >> except: >> print "Connection error" >> >> and presumably we think your code is hanging inside the requests.post >> call? You should probably try to verify that, because if it is elsewhere >> you need to figure out where (lots of print statements is a first start on >> that). >> >> I would open two terminals. Run your program until it hangs in one. >> >> While it is hung, examine the network status. I'll presume you're on a >> UNIX system of some kind, probably Linux? If not it may be harder (or just >> require someone other than me). >> >> If it is hung in the .post call, quite possibly it has an established >> connecion to the target server - maybe that server is hanging. >> >> The shell command: >> >> netstat -rn | fgrep 172.16.68.6 | fgrep 8090 >> >> will show every connection to your server hosting the URL " >> http://172.16.68.6:8090/login.xml". That will tell you if you have a >> connection (if you are the only person doing the connecting from your >> machine). >> >> If you have the "lsof" program (possibly in /usr/sbin, so >> "/usr/sbin/lsof") you can also examine the state of your hung Python >> program. This: >> >> lsof -p 12345 >> >> will report on the open files and network connections of the process with >> pid 12345. Adjust to suit: you can find your program's pid ("process id") >> with the "ps" command, or by backgrounding your program an issuing the >> "jobs" command, which should show the process id more directly. >> >> >> Cheers, >> Cameron Simpson