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
Import private httpx modules #209
Conversation
The public api of httpx has changed in version 0.12.1. Fixes: #208
I think a |
The public api of httpx has changed in version 0.12.1. Fixes: #208
@lepture could you please get this fix merged? This is a blocking bug for me. |
@pdiwan you can use the old version of httpx. It shouldn't be a blocking issue. |
I could but just trying to avoid hardcoding versions now and later change when the fix is merged. |
@@ -1,5 +1,8 @@ | |||
from httpx import URL | |||
from httpx.content_streams import ByteStream | |||
try: | |||
from httpx._content_streams import ByteStream |
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 don't think it is a good idea to import from private modules. I need to ask @encode team to make it public.
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.
So, it's not obvious to me that the rebuild_request
function needs to be written in a way that uses private API here. Can you change that function instead? Perhaps like so...
def rebuild_request(request, url, headers, body):
method = request.method
headers = Headers(request.headers)
headers.update(headers)
return Request(method=method, url=url, headers=headers, body=body)
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.
@tomchristie unfortunately, there is no body
parameter in Request
.
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.
Let me rephrase that. content=...
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.
@tomchristie there is no content
either, the only available parameter would be data=
(I think). But this rebuild_request
is used in auth_flow
, and it is requires_request_body = True
. The request
returned by rebuild_request
is not read
or aread
yet, thus this request
would not have .content
property.
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.
@tomchristie it would also be helpful if we can add a property setter on Request
:
@content.setter
def content(self, value: bytes) -> None:
self._content = value
self.stream = ByteStream(self._content)
Do you think it is ok to add this setter?
Please pin httpx version. |
try: | ||
from httpx._dispatch.base import AsyncDispatcher | ||
except ImportError: | ||
from httpx.dispatch.base import AsyncDispatcher |
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 module will be changed again in v0.13. That's why I'd like to keep our current implementation.
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.
An alternative to using the private dispatch API here would be to implement the stubs as either ASGI or WSGI applications, and use Client(app=wsgi_app)
or AsyncClient(app=asgi_app)
.
The public api of httpx has changed in version 0.12.1.
Fixes: #208
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
If yes, please describe the impact and migration path for existing applications:
Not compatible withEDIT: Fixed with 116988b as suggested by @phy25 in Import private httpx modules #209 (comment)httpx<0.12.0
: thehttpx
library has to be updated to a version>=0.12.0
in existing applications.httpx
: as explained in incompatibility with new httpx version #208. I hope somebody will come up with a better solution than mine!