Live data from Hacker News

Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code

github.com

1–10 of 62 posts

Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code

#1
Hi,

I created httpdbg, a tool for Python developers to easily debug HTTP(S) client requests in Python programs.

I developed it because I needed a tool that could help me trace the HTTP requests sent by my tests back to the corresponding methods in our API client.

The goal of this tool is to simplify the debugging process, so I designed it to be as simple as possible. It requires no external dependencies, no setup, no superuser privileges, and no code modifications.

I'm sharing it with you today because I use it regularly, and it seems like others have found it useful too—so it might be helpful for you as well.

Hope you will like it.

cle

Source: https://github.com/cle-b/httpdbg

Documentation: https://httpdbg.readthedocs.io/

A blog post on a use case: https://medium.com/@cle-b/trace-all-your-http-requests-in-py...

Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code
github.com

Re: Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code

#4
post #3

Is there a way to use it with jupyter notebooks? `pyhttpdbg -m jupyter notebook` didn't work for me

If you want to trace the HTTP requests in a notebook, you must install the package notebook-httpdbg.

This is documented here: https://httpdbg.readthedocs.io/en/latest/notebook/

Re: Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code

#5

this is very useful, but why can it only work with python code? At which level does it intercept the http traffic? do I have to use specific http library?

It seems to intercept calls for some popular http client libs:

https://github.com/cle-b/httpdbg/tree/main/httpdbg/hooks

Re: Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code

#7
This is great -

It would be good to be be able to have django debug toolbar integration, that way I could see which requests were made to backend APIs without leaving Django.

Having tried MITMProxy something like httpdbg is definitely needed.

Re: Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code

#8

this is very useful, but why can it only work with python code? At which level does it intercept the http traffic? do I have to use specific http library?

It works only with Python code because it intercepts HTTP requests by hooking into certain Python functions.

It supports any HTTP library based on Python’s standard socket library. Specifically, it works with libraries like requests, httpx, aiohttp, and urllib3, as well as pytest, providing more detailed information about the initiator of the requests.

Re: Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code

#9
I could be lost here (C/PHP/Node coder mainly in code I've used)

Why is it a special case to track HTTP/s requests, that otherwise couldn't be logged like any other process/function? I'd guess most people use libcurl and you can wrap something around that.

I guess I'm lost on why this is HTTP or Python specific, or if it is, fine.

Re: Show HN: Httpdbg – A tool to trace the HTTP requests sent by your Python code

#10
Looks neat!

A similar tool for this would be VCR (originally built in Ruby, but ported to other languages since): https://vcrpy.readthedocs.io/en/latest/. This injects itself into the request pipeline, records the result in a local file which can then also be replayed later in tests. It's a quite nice approach when you want to write tests (or just explore) a highly complicated HTTP API without actually hitting it all the time.

Post reply on HN