Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I examine the network communications of the Python HTTP Client?

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?

like image 518
chernevik Avatar asked Dec 19 '11 21:12

chernevik


People also ask

What does HTTP client do in Python?

client” module of python first at the start of your python code. After this, the HTTP. client module is used to call the “HTTPConnection()” function to make a connection with a specified URL. The Google URL has been used here.


Video Answer


2 Answers

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

like image 175
Jessedc Avatar answered Oct 31 '22 17:10

Jessedc


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

like image 27
Luka Rahne Avatar answered Oct 31 '22 15:10

Luka Rahne