Skip to content

Instantly share code, notes, and snippets.

@tobami
Created March 15, 2011 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobami/871255 to your computer and use it in GitHub Desktop.
Save tobami/871255 to your computer and use it in GitHub Desktop.
codespeed/tools/save_single_result.py with exception catching
try:
f = urllib2.urlopen(SPEEDURL + 'result/add/', params)
response = f.read()
f.close()
except urllib2.URLError, e:
if hasattr(e, 'reason'):
response = '\n We failed to reach a server\n'
response += ' Reason: ' + str(e.reason)
elif hasattr(e, 'code'):
response = '\n The server couldn\'t fulfill the request\n'
response += ' Error code: ' + str(e)
print "Server (%s) response: %s\n" % (SPEEDURL, response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment