From 8415ef60e228b81d7343c96b016ad21805bba375 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Fri, 13 May 2011 20:31:46 +0200 Subject: some more error handling. esp 413, Request Entity Too Large --- issues.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/issues.py b/issues.py index fdc2300..219ec91 100755 --- a/issues.py +++ b/issues.py @@ -25,14 +25,14 @@ soup = BeautifulStoneSoup(open(xml_file_name, 'r'), convertEntities=BeautifulSto trackers = soup.document.find('trackers', recursive=False).findAll('tracker', recursive=False) from urllib import urlencode -from urllib2 import Request, urlopen +from urllib2 import Request, urlopen, HTTPError from base64 import b64encode from time import sleep from getpass import getpass import re -def rest_call(before, after, data_dict=None): - global github_user, github_password +def __rest_call_unchecked(before, after, data_dict=None): + global github_repo, github_user, github_password url = 'https://github.com/api/v2/xml/%s/%s/%s' % (before, github_repo, after) if data_dict is None: data = None @@ -47,6 +47,21 @@ def rest_call(before, after, data_dict=None): sleep(1) return response +def rest_call(before, after, data_dict=None): + while True: + try: + return __rest_call_unchecked(before, after, data_dict) + except HTTPError, e: + print "Got HTTPError:", e + if e.code == 413 and data_dict: # Request Entity Too Large + l = max(map(len, data_dict.itervalues())) + assert l > 0 + print "Longest value has len", l, "; now we are trying with half of that" + l /= 2 + data_dict = dict(map(lambda (k,v): (k,v[0:l]), data_dict.iteritems())) + continue + raise e # reraise, we cannot handle it + def labelify(string): return re.sub(r'[^a-z0-9._-]+', '-', string.lower()) @@ -105,7 +120,7 @@ def handle_tracker_item(item, issue_title_prefix): followup.details.string, ])) - print 'Creating: %s [%s] (%d comments)%s' % (title, ','.join(labels), len(comments), ' (closed)' if closed else '') + print 'Creating: %s [%s] (%d comments)%s for SF #%s' % (title, ','.join(labels), len(comments), ' (closed)' if closed else '', item.id.string) response = rest_call('issues/open', '', {'title': title, 'body': body}) issue = BeautifulStoneSoup(response, convertEntities=BeautifulStoneSoup.ALL_ENTITIES) number = issue.number.string -- cgit v1.2.1