-
-
Notifications
You must be signed in to change notification settings - Fork 628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't hard code expecting HTTP 200 as the only success response code, all 20x responses are success codes. #8102
Conversation
calling out the original change: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
3d97756
to
ba717e8
Compare
063003c
to
8856db5
Compare
@@ -398,12 +398,14 @@ def do_post(url, num_redirects_allowed): | |||
cookies=cookies.get_cookie_jar(), allow_redirects=False) | |||
if res.status_code in {307, 308}: | |||
return do_post(res.headers['location'], num_redirects_allowed - 1) | |||
elif res.status_code != 200: | |||
elif 300 <= res.status_code < 400 or res.status_code == 401: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all might be a bit less awkward if the 1st check was for ok, ie:
if res.ok:
return True
elif res.status_code in {307, 308}:
return do_post(res.headers['location'], num_redirects_allowed - 1)
else:
error(f'HTTP error code: {res.status_code}. Reason: {res.reason}.')
if 300 <= res.status_code < 400 or res.status_code == 401:
print(f'Use `path/to/pants login --to={auth_provider}` to authenticate '
'against the stats upload service.', file=sys.stderr)
return False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsirois this won't work, since 307 and 307 are also considered ok responses, and we want to treat those as errors.
https://github.com/psf/requests/blob/master/requests/models.py#L702
https://github.com/psf/requests/blob/a4c18cd733f97b5659a29589432d8a39e7a0de87/requests/models.py#L933-L936
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is actually a test to validate that HTTP 307 results in an error:
https://github.com/pantsbuild/pants/pull/8102/files#diff-9e6ae65d103fa02ecc6e5f0ce5eeb3d7L57
… all 20x responses are success codes.
@asherf the error in the 'OSX platform-specific tests (Py3.6 PEX)' shard are persistent: https://travis-ci.org/pantsbuild/pants/jobs/567969022:
The API complained about here is correct on master: result = self._scheduler._native.lib.capture_snapshots(
self._scheduler._scheduler,
self._session,
self._scheduler._to_value(_PathGlobsAndRootCollection(path_globs_and_roots)),
) I tried nuking Travis caches for your branch though and this persists. Perhaps try re-basing your branch against master to kick off a new CI run. I've just freshly nuked Travis caches for your PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay - CI green. I'll merge post haste.
yay!!! |
Problem
Pants treats non-200 HTTP responses from the server as errors. 20x HTTP responses should not be considered errors.
Solution
Use the request's library built in response.ok property to determine if we got an HTTP error response or not.
Result
HTTP 20x responses are handled is valid success responses.