一段时间后禁止Koshuke Github API 403

时间:2019-04-01 06:37:27

标签: java spring github-api

我大约有20个github,我使用koshuke GitHub API更新了一些信息:

try {
    settings = settingsRepository.findById(1).orElseThrow(() -> new RuntimeException("No settings found"));
    GitHub gitHub = GitHub.connect(settings.getUsername(), settings.getToken());

    GHRepository repo;
    try {
        repo = gitHub.getRepository(gitHubModel.getUser() + "/" + gitHubModel.getRepo());
    } catch (Exception e) {
        e.printStackTrace();
        throw new GitHubRepositoryException("Couldn't connect to " + gitHubModel.getLink() + ". Check URL.");
}

有一个事件,每2-3秒围绕它们循环一次,使用其中一个github,对其进行更新,然后在2-3秒后继续到下一个。经过一定数量的更新后,代码将停在:

repo = gitHub.getRepository(gitHubModel.getUser() + "/" + gitHubModel.getRepo());. 

我尝试调试,发现它在某个时间点停止并抛出403 Forbidden:

private <T> T parse(Class<T> type, T instance, int timeouts) throws IOException {
    InputStreamReader r = null;
    int responseCode = -1;
    String responseMessage = null;
    try {
        responseCode = uc.getResponseCode();
        responseMessage = uc.getResponseMessage();
        if (responseCode == 304) {
            return null;    // special case handling for 304 unmodified, as the content will be ""
        }
        if (responseCode == 204 && type!=null && type.isArray()) {
            // no content
            return type.cast(Array.newInstance(type.getComponentType(),0));
        }

        r = new InputStreamReader(wrapStream(uc.getInputStream()), "UTF-8");
        String data = IOUtils.toString(r);
        if (type!=null)
            try {
                return setResponseHeaders(MAPPER.readValue(data, type));
            } catch (JsonMappingException e) {
                throw (IOException)new IOException("Failed to deserialize " +data).initCause(e);
            }
        if (instance!=null) {
            return setResponseHeaders(MAPPER.readerForUpdating(instance).<T>readValue(data));
        }
        return null;
    } catch (FileNotFoundException e) {
        // java.net.URLConnection handles 404 exception has FileNotFoundException, don't wrap exception in HttpException
        // to preserve backward compatibility
        throw e;
    } catch (IOException e) {
        if (e instanceof SocketTimeoutException && timeouts > 0) {
            LOGGER.log(INFO, "timed out accessing " + uc.getURL() + "; will try " + timeouts + " more time(s)", e);
            return parse(type, instance, timeouts - 1);
        }
        throw new HttpException(responseCode, responseMessage, uc.getURL(), e);
    } finally {
        IOUtils.closeQuietly(r);
    }
}

然后,该异常被消耗,并到达调用Thread.sleep的位置并在那里停止。 这是因为我超出了请求的限制吗?我读过某个地方,这是一分钟5000个请求,而我没有做那么多。任何想法为什么会这样吗?

0 个答案:

没有答案