5

I'm trying to isolate a bug that exists either in Python's httplib2 HTTP client or an API. (First guess is the API.) While using httplib2 to POST data to a RESTful API, I'm getting a 401 response status (no authorization) and saving data to the API.

I'd like to examine the HTTP request and response to the client, the very strings put onto and received from the network. The httplib2 code seems too involved to easily capture the values from within it, and might possibly miss the bug.

It seems quicker to look at the network communications with the client. Is there some tool I can use to monitor the client's communications with the local network socket?

chernevik
  • 3,922
  • 9
  • 41
  • 55
  • [Wireshark](http://www.wireshark.org/) – JBernardo Dec 19 '11 at 21:35
  • Does changing [`httplib2.debuglevel`](http://bitworking.org/projects/httplib2/doc/html/libhttplib2.html#httplib2.debuglevel) not produce anything useful? – David Alber Dec 19 '11 at 21:37
  • how can your client be at fault if the server is both returning a 401 status *and* saving the data POSTed to it? – matt b Dec 19 '11 at 22:21
  • There is the possibility that the client is somehow borking the status code. I don't think that's _likely_, but I'd like to know how to exclude it. – chernevik Dec 20 '11 at 01:20
  • Also, the same data and headers get status 201 when sent via curl. So even if there is a bug at the API, there is something in the python client request that triggers it not present in other requests that go cleanly. That hardly means python is at fault, but if it's something I can hack while the maintainers fiddle with their api, that'd be nice to know. – chernevik Dec 20 '11 at 01:30

2 Answers2

4

I use http://www.charlesproxy.com for all my network debugging.

Jessedc
  • 12,320
  • 3
  • 50
  • 63
  • 1
    Took a little while to figure out usage, but this did what I was looking for. Noobs like myself: Capturing traffic with curl / python requires enabling SSL Proxying within Charles for your target host (possibly different ways for different clients), and routing your curl / python requests through the localhost proxy provided by Charles. Which now seems defaulted to port 8888, rather than the 8080 mentioned in documentation. – chernevik Jan 02 '12 at 22:28
  • How do you route python requests through the Charles proxy without changing the source code of the libs you're using? – Anentropic Dec 06 '12 at 13:52
  • my bad... you have to specifically add the domains you want to proxy in Charles SSL config, to capture https requests, then it works transparently for python – Anentropic Dec 06 '12 at 13:56
2

http://www.wireshark.org/ enables you to monitor local sockets too. I was able to monitor local loopback even on windows using trick whit adding route.

http://wiki.wireshark.org/CaptureSetup/Loopback check Other Alternatives

Or you can just write raw socket server that listen on client side on one port and send data to server on other port and vice versa and prints out all data. It should not take more than dozen of lines of code

Luka Rahne
  • 10,336
  • 3
  • 34
  • 56