See the HTTP requests your script makes, without changing it
My morning brief script found only 2 stories on my topics yesterday. The day before, it found 4. Was the API's answer different, or is my filter wrong? How do you find out? You add print(resp.read()) to the script, run it, and get one 200 KB line of JSON in your terminal. You also want the headers, so you add more prints. If the script used curl , you'd add -v and read TLS handshake lines. Either…
To understand what a script does without altering it, you can use a tool called cmdbook. By enabling capture for the command in its settings, cmdbook operates quietly in the background. It establishes a proxy that the script interacts with while pointing at the proxy, all while handling the necessary configuration for HTTPS, such as certificates.
This process allows you to observe each request the script makes, including its method, URL, and status code. For the example given, the script performed a GET request to a specific URL and received a 200 OK response. By examining the detailed breakdown provided by cmdbook, you can discern that only a small portion of the articles on the front page matched the script's specified topics.
This investigation reveals that the filter was properly configured; the lack of matches was due to the script being run during a period of low activity for those topics. Cmdbook supports a wide range of command-line tools, such as curl, wget, Python libraries like urllib, requests, and httpx, as well as most standard command-line utilities.
However, it does not intercept requests handled without proxy variables, such as Node's built-in fetch. It is worth noting that cmdbook's HTTP Capture feature is part of the Pro subscription, which enables users to explore and analyze their scripts' interactions with web services without the need to modify the scripts themselves or introduce additional tools.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to