-
Notifications
You must be signed in to change notification settings - Fork 186
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
Adds a monkeypatch() function that ensures all Sessions use the AppEngineAdapter compatibility class. #119
Conversation
And once/if this is merged, I'll request that feature/gae be merged into master as well. |
I think this is a reasonable stop-gap solution to this problem. It would be nice if there was a better way to do this though. Class-level variables on the |
I agree class-level variables on the Session would be better. However, even if we fixed that in requests library, we'd still probably want need to support backwards-compatibility with older versions of the request library, so this code would still be necessary anyway, right? So I viewed that improvement as a non-blocker for this change. |
Yup, it's definitely a non-blocker. |
af81f8a
to
85dc8bf
Compare
As requested in urllib3/urllib3#763 , I've moved most of that complexity into this requests-toolbelt patch instead. The urllib3 changes have been merged, so hopefully @sigmavirus24 or @Lukasa can have another look here. Thanks! |
redirect=True, assert_same_host=True, timeout=timeout.Timeout.DEFAULT_TIMEOUT, | ||
pool_timeout=None, release_conn=None, **response_kw): | ||
# Jump through the hoops necessary to call AppEngineManager's API. | ||
appengine_manager = gaecontrib.AppEngineManager( |
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.
wouldn't it be better to just create this once?
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.
Good idea, fixed. Though really, the way this code gets used, I believe urlopen was only called once per connection anyway. (Though see note in next comment, as that assumption could change.)
I'm confused and hoping someone can clarify this for me. I've checked out requests-toolbelt, applied patches 114 and 119, and am referencing that modified version of requests-toolbelt from my project. I am unclear whether I am supposed to also apply 763 to urllib3, I have not yet done this. I also added the When I try to run my project, I get:
I feel like I'm missing something obvious here... can someone point me at my oversight? |
@seawolf42 Yes, you need to patch 763 into request's version of urllib3. For background, 763 was merged into urllib3, but requests has its own version of urllib3, and the urllib3 head hasn't been integrated there yet. Once the requests-toolbelt changes go in, I will push harder on getting someone to merge that. |
""" | ||
|
||
def __init__(self, pool_manager, url): | ||
self.appengine_manager = gaecontrib.AppEngineManager( |
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.
Could you have the pool_manager
construct this and pass it down to each connection?
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.
Great idea, fixed.
@Lukasa, @sigmavirus24 I'm satisfied with this, if you guys want to take a look. |
@mikelambert, thanks, that did the trick! I can confirm that using just these three patches (114 and 119 on requests-toolbelt and 763 on urllib3 within request) I am able to use python-social-auth on GAE with DjangoAppEngine, at least within the dev server. |
This looks reasonable to me. =) |
@seawolf42 Did you succeed in production as well not only on the dev server? |
@jonathan-s have you tested this and found problems? If so, please let us know so we can have this in the best shape possible before merging. |
I haven't tested it, I'll try to make some tests and see what I get. |
UPDATE: Not an issue.
I got this traceback:
|
Seeing now that it might be because of the internal use of request which uses an earlier version urllib3 |
This is working great in production with both python-social-auth and facebook-sdk packages. |
I got it working as well. so 👍 for this. |
or if you use libraries that call the requests API directly (ie requests.post), | ||
then you may prefer to monkeypatch and auto-configure all newly-constructed Sessions. | ||
""" | ||
# HACK: We should consider modifying urllib3 to support this as an explicit module-level variable. |
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 comment doesn't make sense.
Thank you @seawolf42 and @jonathan-s for testing this for us. |
Okay, should have made all the changes you've requested. I believe all failing tests are now unrelated to my changes. And it will be harder to test and verify this code now (like was done earlier up-thread), because there is no 2.10.0 requests library yet. :) |
ad79242
to
a22395f
Compare
Could you rebase this please? |
5005ea7
to
584501e
Compare
…gineAdapter compatibility class. Implement urllib3 wrappers that let requests work on appengine.
584501e
to
302e570
Compare
Rebased. |
Adds a monkeypatch() function that ensures all Sessions use the AppEngineAdapter compatibility class.
Thanks @mikelambert |
Thanks! Curious, what's the next step here? Push requests to release 2.10.0 with the latest urllib3, and then after you can integrate feature/gae into master? |
Please don't push requests to do anything. Speaking as a maintainer there, we're already aware this is a desirable feature. Because of the version checking that takes place in the code now, we can actually release the toolbelt when it's ready. I just need to merge (at least) 2 PRs before performing a release here. |
The goal here is to allow the following code to work:
...and then run all your libraries that have dependencies on requests and sessions buried deep inside, all working properly with URLFetch on Appengine.
The code doesn't work as-is, as it depends on the following change:
urllib3/urllib3#763
...which then would probably need to be released and ported into the requests library as well...not sure how long that takes or what the process is.
This also is tangentially related to the following issues relating to getting requests playing nicely with AppEngine's URLFetch:
https://github.com/kennethreitz/requests/issues/1905
urllib3/urllib3#618