ConnectionError handling problem

Gonzalo V gvm2121 at
Sat Sep 26 15:46:34 CEST 2015

Hi Cameron.
i had the same problems and you have to tell to python what to do with the
connect problem.
try this:

except *urllib.error.HTTPError* as e:
            if e.getcode()==504:
                disp = "SIN RESPUESTA DEL SERVIDOR" #(No answer from the


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.

greeting from Chile. Sorry my english.


2015-09-25 3:24 GMT-04:00 Cameron Simpson <cs at>:

> On 24Sep2015 22:46, shiva upreti <katewinslet626 at> wrote:
>> On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson
>> wrote:
>>> On 24Sep2015 20:57, shiva upreti <katewinslet626 at> 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:
>, data=query_args)
>  except:
>    print "Connection error"
> and presumably we think your code is hanging inside the
> 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 | fgrep 8090
> will show every connection to your server hosting the URL "
>". 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 <cs at>
> --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list