<div dir="ltr">Hi Cameron.<div>i had the same problems and you have to tell to python what to do with the connect problem.</div><div>try this:</div><div><br></div><div>...</div><div><div>except <b><u>urllib.error.HTTPError</u></b> as e:</div><div>            if e.getcode()==504:</div><div>                disp = "SIN RESPUESTA DEL SERVIDOR" #(No answer from the server)</div><div>                nombre=''</div><div>                origen=''</div><div><br></div><div>                precioAhora=''</div><div>                print(e.getcode(),disp)</div><div>                pass</div></div><div><br></div><div><br></div><div>that works for me. You can handle any error. 404, and 500 and more. but you have to tell him to python what to do.</div><div><br></div><div>greeting from Chile. Sorry my english.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">Saludos,<br>Gonzalo</div></div>
<br><div class="gmail_quote">2015-09-25 3:24 GMT-04:00 Cameron Simpson <span dir="ltr"><<a href="mailto:cs@zip.com.au" target="_blank">cs@zip.com.au</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 24Sep2015 22:46, shiva upreti <<a href="mailto:katewinslet626@gmail.com" target="_blank">katewinslet626@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 24Sep2015 20:57, shiva upreti <<a href="mailto:katewinslet626@gmail.com" target="_blank">katewinslet626@gmail.com</a>> wrote:<br>
>Thank you Cameron.<br>
>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.<br>
</blockquote></blockquote>
<br></span><span class="">
Ok. You original code says:<br>
<br>
 try:<br>
   r=requests.post(url, data=query_args)<br>
 except:<br>
   print "Connection error"<br>
<br></span>
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).<br>
<br>
I would open two terminals. Run your program until it hangs in one.<br>
<br>
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).<br>
<br>
If it is hung in the .post call, quite possibly it has an established connecion to the target server - maybe that server is hanging.<br>
<br>
The shell command:<br>
<br>
 netstat -rn | fgrep 172.16.68.6 | fgrep 8090<br>
<br>
will show every connection to your server hosting the URL "<a href="http://172.16.68.6:8090/login.xml" rel="noreferrer" target="_blank">http://172.16.68.6:8090/login.xml</a>". That will tell you if you have a connection (if you are the only person doing the connecting from your machine).<br>
<br>
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:<br>
<br>
 lsof -p 12345<br>
<br>
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.<div class="HOEnZb"><div class="h5"><br>
<br>
Cheers,<br>
Cameron Simpson <<a href="mailto:cs@zip.com.au" target="_blank">cs@zip.com.au</a>><br>
-- <br>
<a href="https://mail.python.org/mailman/listinfo/python-list" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div>