⚡ Solution Summary

  • Change the default HTTP client to prioritize requests over urlfetch.
  • Ensure the environment is correctly set for Google App Engine.
  • Review usage of urlfetch in testing environments.
### Describe the bug _http_client.py [declares](https://github.com/stripe/stripe-python/blob/master/stripe/_http_client.py#L42-L45) that "Requests is the preferred HTTP library"; however, urlfetch is chosen before requests when creating a default http client. Additionally, the current ordering throws an error when `appengine-python-standard` is installed. ### To Reproduce 1. `pip install appengine-python-standard` 2. `pip install stripe` 3. Initialize stripe client ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys stripe.api_key = '<your-api-key-here>' ``` 5. Create a verification session ```python verification_session = stripe.identity.VerificationSession.create( type="document", ) ``` 6. Error `AssertionError: No api proxy found for service "urlfetch"` ### Expected behavior requests is chosen over urlfetch as default HTTP library. ### Code snippets _No response_ ### OS macOS ### Language version Python 3.12.4 ### Library version 10.8.0 ### API version 2024-06-20 ### Additional context [PR #1378 ](https://github.com/stripe/stripe-python/pull/1378)

Discussion & Fixes

richardm-stripe 2024-08-26
Hello @nanewalt. I think this behavior is intended. The idea is that, if `google.appengine.api` is present in the environment, then your app is probably running in Google App Engine and in this case most users would probably prefer to use the appengine-provided `urlfetch` over `requests`. The error you are seeing happens when you try and use `urlfetch` outside of google app engine -- which I'm guessing is because you are running a test suite or something outside of Google? There are some notes about using urlfetch in a testing environment in [this thread](https://groups.google.com/g/google-appengine/c/B8fNG6vESE0). Alternatively, if you want to override the default precedence and use Requests anyway then you have to [explicitly initialize](https://github.com/stripe/stripe-python?tab=readme-ov-file#configuring-an-http-client) a Requests client (see the [old README](https://github.com/stripe/stripe-python/tree/v7.0.0?tab=readme-ov-file#configuring-a-client) if you haven't [upgraded to StripeClient](https://github.com/stripe/stripe-python/wiki/Migration-guide-for-v8-(StripeClient)) yet) Does that make sense? I definitely see how the comment in the source code could be a little misleading and will correct that.
richardm-stripe 2024-08-26
Preemptively closing as we've taken action and changed the misleading comment. Please feel free to re-open if you have concerns.

Get updates

We publish verified fixes weekly. No spam.

Subscribe