Support HTTP Proxy on BookWorm#10310
Merged
mekarpeles merged 2 commits intointernetarchive:masterfrom Jan 10, 2025
Merged
Conversation
Closes internetarchive#10230 This commit allows BookWorm to use the HTTP proxy when fetching metadata from Amazon. BookWorm relies on an Amazon API client that itself relies on `urllib3` which explictly does not and will not support the HTTP_PROXY environment variable. `urllib3` does support HTTP Proxies, but it needs a specific object, and the underlying code for the API does support all of this, but the library provides no way to pass the proxy value through to `urllib3`. The workaround here is to create the `Configuration` object in the Amazon API client, add a proxy object after init, then use that to create a REST client, and then replace the original `api_client` object with this one, so that there is proxy support. Note: if trying to create an `vendors.AmazonAPI` object in a REPL, one will need the 'magic incantation' with `infogami._setup()` after the config has been loaded, or the `http_proxy_url` value will be `None`.
mekarpeles
reviewed
Jan 10, 2025
| """ | ||
| Creates an instance containing your API credentials. | ||
|
|
||
| Instantiating this object in a REPL requires the `infogami._setup()` |
scottbarnes
added a commit
to scottbarnes/openlibrary
that referenced
this pull request
Jan 12, 2025
* Support HTTP Proxy on BookWorm Closes internetarchive#10230 This commit allows BookWorm to use the HTTP proxy when fetching metadata from Amazon. BookWorm relies on an Amazon API client that itself relies on `urllib3` which explictly does not and will not support the HTTP_PROXY environment variable. `urllib3` does support HTTP Proxies, but it needs a specific object, and the underlying code for the API does support all of this, but the library provides no way to pass the proxy value through to `urllib3`. The workaround here is to create the `Configuration` object in the Amazon API client, add a proxy object after init, then use that to create a REST client, and then replace the original `api_client` object with this one, so that there is proxy support. Note: if trying to create an `vendors.AmazonAPI` object in a REPL, one will need the 'magic incantation' with `infogami._setup()` after the config has been loaded, or the `http_proxy_url` value will be `None`. --------- Co-authored-by: Scott Barnes <scott.barnes@archive.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10230
This commit allows BookWorm to use the HTTP proxy when fetching metadata from Amazon.
BookWorm relies on an Amazon API client that itself relies on
urllib3which explicitly does not and will not support the HTTP_PROXY environment variable.urllib3does support HTTP Proxies, but it needs a specific object, and the underlying code for the API does support all of this, but the library provides no way to pass the proxy value through tourllib3.The workaround here is to create the
Configurationobject in the Amazon API client, add a proxy object after init, then use that to create a REST client, and then replace the originalapi_clientobject with this one, so that there is proxy support.Note: if trying to create an
vendors.AmazonAPIobject in a REPL, one will need the 'magic incantation' withinfogami._setup()after the config has been loaded, or thehttp_proxy_urlvalue will beNone.Testing
This isn't easy to test, but the following will work from
ol-home0, inside the testing affiliate server container, as this code is currently applied there (onceamz_keyandamz_secrethave the relevant values:Without this PR, request for
amazon.get_product()will simply time out.NOTE: this does NOT fix the
/isbnendpoint. That still is not working for an unknown reason, and is the next follow up to this.Stakeholders
@mekarpeles