-
Notifications
You must be signed in to change notification settings - Fork 107
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
Requests reloaded #199
base: master
Are you sure you want to change the base?
Requests reloaded #199
Conversation
musicbrainzngs/musicbrainz.py
Outdated
raise AuthenticationError(cause=exc) | ||
raise ResponseError(cause=exc) | ||
except requests.RetryError as exc: | ||
raise NetworkError(cause=exc) |
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.
I could have this wrong, but it looks on my machine like RetryError
is in the requests.exceptions
module, not just in requests
:
>>> requests.__version__
'2.9.1'
>>> requests.RetryError
Traceback (most recent call last):
File "<input>", line 1, in <module>
requests.RetryError
AttributeError: 'module' object has no attribute 'RetryError'
>>> requests.exceptions.RetryError
<class 'requests.exceptions.RetryError'>
Also, I noticed that RetryError
inherits from RequestException
, so it would have the same effect to just fall through to the next except
handler.
Woohoo! Thanks for reviving this. I reviewed the diff and it looks great to me—I can give it a try with a beets import sometime soon too. |
Cool! I've mellowed in my beliefs since the last time this patch was proposed. I see no problem in going for it. @mineo, do you want to coordinate merging? |
@alastair Sure, I can do that. Do you want me to merge it to master and make the next version the API change one or keep this on a separate branch on the off-chance that we'll get around to tackling some of the other API change tickets at some point in the near future? |
Hmm. If we do this right, this change shouldn't affect the external API, right? I'd really like to get a release out adding features for all of the outstanding schema changes before we start playing with the external API. What other options are there? We could run 2 APIs in parallel, and you can "turn on" the old one by changing an import? It was 3 (!) years ago that I last said it (#116 (comment)), but I still don't like APIs changing under me from one version to another, even if the version number is "not stable". What do you think? |
The only externally visible change is the one mentioned in To be honest, I'd rather keep things as they are and shelve this pull request until we're changing interfaces for some other reason instead of maintaining 2 APIs. |
Hi! I'd like to revive the requests discussion if folks here are interested. In particular, we'd really like to switch beets to use OAuth2 instead of storing a password in plaintext. This has turned out to be relatively easy to prototype using requests (see the beets PR above) and relatively hard to do without it. So, instead of dropping python-musicbrainzngs for the part of the code that needs to use OAuth2, we'd love to merge that support into the library. How are folks feeling about a requests-based release that, as its raison detre, also adds OAuth authentication? We (speaking collectively for the beets project) would be happy to contribute as much code as we can if people are amenable to seeing the such a release in a "soonish" time frame. |
requests also has SNI support, right? So the library could default to being all HTTPS and not worry about Python <2.7.9? Either way, my vote (FWIW) is to just do it. As mentioned in #123 the library is still a version 0.x, so not officially stable (going by SemVer), and the backwards incompatibility incurred with this switch is minor. |
The requests FAQ seems to indicate that it probably supports SNI, depending on the dependencies: Anyway, yes! That would be a great knock-on effect. What do you think, @alastair? |
0562f8c
to
b8b9796
Compare
Hey everyone, Do we know what the API differences are going to be, if any? I thought that maybe #85 would be a problem, but this happens after the data is downloaded, and so I think that switching to requests won't affect this. I would argue that the library has been around too long to use semver as an excuse for making incompatible changes without a good reason. If we can show that changing to requests results in no difference in the way that it's called, then we should merge this as soon as possible (e.g. perhaps if tests still pass and beets can show that there was no required changes to the API to work with requests) |
Cool! I'll give this a try, do a thorough code review, and run some tests. I think the only visible change is the one @mineo mentioned above: the cause field of exceptions, which expose the underlying network exceptions. Seems pretty minor. I'll start adding OAuth support once that's ready in a separate PR. |
|
||
# Don't import Retry from urllib3 directly, this only works correctly the Retry | ||
# class form the urllib3 package requests vendors in is used. | ||
from requests.packages.urllib3.util.retry import Retry |
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.
Ignoring the typos in the docstring above, requests recently unvendored all its external dependencies, so this code here should be double-checked (see http://docs.python-requests.org/en/latest/community/updates/#id9).
Signed-off-by: Adrian Sampson <[email protected]>
Use the requests_mock package to install its own adapter into requests and assert certain properties on the URLs opened by requests. Signed-off-by: Wieland Hoffmann <[email protected]>
Signed-off-by: Wieland Hoffmann <[email protected]>
Signed-off-by: Wieland Hoffmann <[email protected]>
Signed-off-by: Wieland Hoffmann <[email protected]>
Signed-off-by: Wieland Hoffmann <[email protected]>
Signed-off-by: Wieland Hoffmann <[email protected]>
Test only the lowest one and the most recent one - let's hope there are no breaking changes in between (there were none at the time of this commit). Signed-off-by: Wieland Hoffmann <[email protected]>
This makes sure proper cleanup happens, even if some unhandled exception was raised. Signed-off-by: Wieland Hoffmann <[email protected]>
Signed-off-by: Wieland Hoffmann <[email protected]>
Signed-off-by: Wieland Hoffmann <[email protected]>
They got lost during rebasing and none of our tests use the codepaths that use them. Signed-off-by: Wieland Hoffmann <[email protected]>
RetryError is a subclass of RequestException, so this was not useful. Signed-off-by: Wieland Hoffmann <[email protected]>
Recent versions of requests no longer accept integer header values. See https://github.com/kennethreitz/requests/issues/3477 Signed-off-by: Wieland Hoffmann <[email protected]>
1ccde2e
to
bbbfead
Compare
Rebased from alastair#199 Co-authored-by: Adrian Sampson <[email protected]> Co-authored-by: Wieland Hoffmann <[email protected]>
Rebased from alastair#199 Co-authored-by: Adrian Sampson <[email protected]> Co-authored-by: Wieland Hoffmann <[email protected]>
Rebased from alastair#199 Co-authored-by: Adrian Sampson <[email protected]> Co-authored-by: Wieland Hoffmann <[email protected]>
Rebased from alastair#199 Co-authored-by: Adrian Sampson <[email protected]> Co-authored-by: Wieland Hoffmann <[email protected]>
Rebased from alastair#199 Co-authored-by: Adrian Sampson <[email protected]> Co-authored-by: Wieland Hoffmann <[email protected]>
This is #123 again, rebased on top of current master and with passing tests ✨
Note that I've bumped the requests dependency to 2.5.0 because that's the first version that allows using urllib3's Retry objects for max_retries on the HTTPAdapter and (afaik) that's the only way to implement retries on a specific set of HTTP status codes. t
Especially the retry/exception part could use a second pair of eyes to make sure everything works as expected and if you have some scripts that make heavy use of pymbngs, please run them with this pull request and see if nothing breaks.