Skip to content
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

Could not hook httpx "event hooks" for debugging #669

Closed
bakkiaraj opened this issue Sep 12, 2022 · 3 comments
Closed

Could not hook httpx "event hooks" for debugging #669

bakkiaraj opened this issue Sep 12, 2022 · 3 comments
Labels
🐞bug Something isn't working

Comments

@bakkiaraj
Copy link

Describe the bug
I like to do deep debugging with the clients generated using openapi-python-client. I would like to see request, response objects for every api call is logged/ dumped for analysis.

From the httpx documentation, its possible using Event Hooks (https://www.python-httpx.org/advanced/).

But I could not successfully able to hook the events.

To Reproduce
Steps to reproduce the behavior:

def log_httpx_request(request: httpx.Request) -> None:
    print ("*** ", type(request))
    print(f"+++Request event hook: {request.method} {request.url} - Waiting for response")


def log_httpx_response(response: httpx.Response) -> None:
    print ("***", type(response))
    request = response.request
    print(f"+++Response event hook: {request.method} {request.url} - Status {response.status_code}")

...
    client = Client(
        base_url="https://codebeamer.xxx.com/cb",
        headers={"Authorization": "Basic " + base64.b64encode(basic_auth_data).decode("ascii")},
        timeout=10.0,
    )

    client.event_hooks={'request': [log_httpx_request], 'response': [log_httpx_response]}

    version_data = get_server_version.sync(client=client)
...

Expected behavior
HTTPx event hook is working but event hook is not called at all.
Looks like event hooks work with httpx client object but the generated code directly uses "httpx.request" helper function.
Please provide a way to do a full debugging / event hooks.

OpenAPI Spec File
NA

Desktop (please complete the following information):

  • OS: Ubuntu 22.04.1 LTS
  • Python Version: Python 3.10.4
  • openapi-python-client version 0.11.5
@bakkiaraj bakkiaraj added the 🐞bug Something isn't working label Sep 12, 2022
@dbanty
Copy link
Collaborator

dbanty commented Sep 12, 2022

It sounds like this will be covered by #202 when implemented, is that correct?

@bakkiaraj
Copy link
Author

@dbanty , Indeed. #202 would solve this issue as well. Thanks. Shall I close this issue?

@dbanty
Copy link
Collaborator

dbanty commented Sep 12, 2022

I think so, if you wouldn’t mind adding your use case to that other issue as well just to +1 support that would be great.

I feel like enough different people have wanted a feature like that that it should be the highest priority 😅

@dbanty dbanty closed this as completed Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants