-
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
[requests_toolbelt.session] Prepared requests do not have the complete url #315
Comments
No, it doesn't |
@sigmavirus24 Is this something that could be added? |
Yes, it is |
@sigmavirus24 Is it ok if I give it a try? |
Absolutely! |
What do you think of this solution?
The copy is so we do not mutate the original Request object |
I don't believe a copy is the right thing to do. Users can have file objects and such and pretending to copy will not preserve anything. |
Oh, ok - so is it fine to just substitute the complete url in the user's Request like this?
|
Yup. That's how I'd expect it to work because all too often those requests can't be reused |
We now override the `prepare_request` method of the Session to generate a complete URL from the session's base URL and a partial resource name. The request is then prepared with the complete URL. >>> from requests import Request >>> from requests_toolbelt import sessions >>> s = sessions.BaseUrlSession( ... base_url='https://example.com/resource/') >>> request = Request(method='GET', url='sub-resource/') >>> prepared_request = s.prepare_request(request) >>> r = s.send(prepared_request) >>> print(r.request.url) https://example.com/resource/sub-resource Closes requests#315.
We now override the `prepare_request` method of the Session to generate a complete URL from the session's base URL and a partial resource name. The request is then prepared with the complete URL. >>> from requests import Request >>> from requests_toolbelt import sessions >>> s = sessions.BaseUrlSession( ... base_url='https://example.com/resource/') >>> request = Request(method='GET', url='sub-resource/') >>> prepared_request = s.prepare_request(request) >>> r = s.send(prepared_request) >>> print(r.request.url) https://example.com/resource/sub-resource Closes requests#315.
This is working:
But this is not:
Does requests_toolbelt have a way to prepare requests with the base url?
The text was updated successfully, but these errors were encountered: