weecology / DeepForest-pytorch

Pytorch implementation of the deepforest model for tree crown RGB detection.
MIT License
16 stars 9 forks source link

How to avoid rate limit download error from github during tests? #36

Open bw4sz opened 3 years ago

bw4sz commented 3 years ago

@henrykironde can you look into something for me? To use the release model in /tests/ we download a file from the latest github release. I make sure to only run

model.use_release()

once in https://github.com/weecology/DeepForest-pytorch/blob/master/tests/conftest.py

and then inherit that fixture in all downstream tests to try to github API problems. Nevertheless, I occasionally get

tests/test_main.py:32: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
deepforest/main.py:61: in use_release
    release_tag, self.release_state_dict = utilities.use_release()
deepforest/utilities.py:66: in use_release
    headers={'Accept': 'application/vnd.github.v3+json'},
/usr/local/miniconda/envs/DeepForest_pytorch/lib/python3.7/urllib/request.py:222: in urlopen
    return opener.open(url, data, timeout)
/usr/local/miniconda/envs/DeepForest_pytorch/lib/python3.7/urllib/request.py:531: in open
    response = meth(req, response)
/usr/local/miniconda/envs/DeepForest_pytorch/lib/python3.7/urllib/request.py:641: in http_response
    'http', request, response, code, msg, hdrs)
/usr/local/miniconda/envs/DeepForest_pytorch/lib/python3.7/urllib/request.py:569: in error
    return self._call_chain(*args)
/usr/local/miniconda/envs/DeepForest_pytorch/lib/python3.7/urllib/request.py:503: in _call_chain
    result = func(*args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <urllib.request.HTTPDefaultErrorHandler object at 0x7fec11aa8350>
req = <urllib.request.Request object at 0x7feb8a288310>
fp = <http.client.HTTPResponse object at 0x7feb6eee1250>, code = 403
msg = 'rate limit exceeded'
hdrs = <http.client.HTTPMessage object at 0x7feb6eee1a50>

    def http_error_default(self, req, fp, code, msg, hdrs):
>       raise HTTPError(req.full_url, code, msg, hdrs, fp)
E       urllib.error.HTTPError: HTTP Error 403: rate limit exceeded

/usr/local/miniconda/envs/DeepForest_pytorch/lib/python3.7/urllib/request.py:649: HTTPError

as in the failed run here

https://github.com/weecology/DeepForest-pytorch/runs/2136417458?check_suite_focus=true

basically because we ask github to check the release too often during tests? Is there an api_key, or maybe something we can mock that might be a workaround? I think this is just a tests problem since they are run in parallel and all communicating with github.

henrykironde commented 3 years ago

Just a note for Ref: #41