def handle_api_error(self, rbody, rcode, resp, rheaders): # Rate limits were previously coded as 400's with code 'rate_limit' if rcode == 429: raise error.RateLimitError( resp.get('detail'), rbody, rcode, resp, rheaders) elif rcode in [400, 404]: type = resp.get('type') if type == 'about:blank': type = None raise error.InvalidRequestError( resp.get('detail'), type, rbody, rcode, resp, rheaders) elif rcode == 401: raise error.AuthenticationError( resp.get('detail'), rbody, rcode, resp, rheaders) else: detail = resp.get('detail') # This information will only be returned to developers of # the OpenAI Gym Scoreboard. dev_info = resp.get('dev_info') if dev_info: detail = "{}\n\n<dev_info>\n{}\n</dev_info>".format(detail, dev_info['traceback']) raise error.APIError(detail, rbody, rcode, resp, rheaders)
def instance_path(self): id = self.get('id') if not id: raise error.InvalidRequestError( 'Could not determine which URL to request: %s instance ' 'has invalid ID: %r' % (type(self).__name__, id), 'id') id = util.utf8(id) base = self.class_path() extn = urllib.quote_plus(id) return "%s/%s" % (base, extn)
def instance_path(self): user_repo = self.get('id', '').split( '/') # id is owner/repository/commit_ref if not len(user_repo) == 3: raise error.InvalidRequestError( 'Could not determine which URL to request: %s instance ' 'has missing id: %r' % (type(self).__name__, 'owner/repository/commit_ref'), None) owner = urllib.parse.quote_plus(util.utf8(user_repo[0])) repository = urllib.parse.quote_plus(util.utf8(user_repo[1])) commit_ref = urllib.parse.quote_plus(util.utf8(user_repo[2])) return "%s/%s/%s/commits/%s" % (self.class_path(), owner, repository, commit_ref)
def instance_path(self): user_repo = self.get('id', '').split('/') # id is username/repository if not len(user_repo) == 2: raise error.InvalidRequestError( 'Could not determine which URL to request: %s instance ' 'has missing id: %r' % (type(self).__name__, 'username/repository'), None) commit_hash = self.get( 'commit_hash', 'master') # Downloading from master branch by default username = urllib.parse.quote_plus(util.utf8(user_repo[0])) repository = urllib.parse.quote_plus(util.utf8(user_repo[1])) commit_hash = urllib.parse.quote_plus(util.utf8(commit_hash)) config_file = urllib.parse.quote_plus(util.utf8(github_yaml_file)) return "/%s/%s/%s/%s" % (username, repository, commit_hash, config_file)