Python Error message

Steven D'Aprano steve+python at pearwood.info
Thu Aug 4 11:56:01 EDT 2016


On Fri, 5 Aug 2016 01:31 am, GBANE FETIGUE wrote:

> try:
>   parsed_response = json.loads(response)
>   deployid  = parsed_response[u'id']
>   print "Your deployid is: " + deployid
> except:
>     print 'Seems the named id  already exists!'


I'm not going to try to debug your code blindfolded with my hands tied
behind my back. Get rid of those "try...except" blocks so that you can see
what error is *actually* happening.

As you have it now, an error happens, somewhere. You don't know where the
error is, or what it is, but Python generates a nice exception showing all
the detail you need to debug.

But you catch that exception, throw it away, and then print a lie.

It is **not true** that the named ID already exists. That is not what the
error is, so why does your script tell a lie?

The output from the server might give you a clue:

"The server refused this request because the request entity is in a format
not supported by the requested resource for the requested method."


Never[1] use a bare "try...except". It is the worst thing you can do to a
Python script, making it almost impossible to debug.

https://realpython.com/blog/python/the-most-diabolical-python-antipattern/

Fix that problem first, get rid of the "try...except" and lying print
messages, and then either the bug will be obvious, or we can debug further.






[1] There are exceptions to this rule, for experts. But if you need to ask
what they are, you're not ready to know.


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list