Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3715

Log REST API calls in Python

$
0
0

I am working on a data processing task in an enterprise environment with Python3 installed on a client-side Windows Jump server.The data, which I need to download regularly from a third-party provider, is accessed via a REST API.The business requirement is that the data (body) received in response should be logged in a way that provides the most credible solution how data is received in its most original form from the third party provider.That is, it must be convincing that what is logged is what is received from them. So we need to develop a solution that eliminates the possibility that we on the receiving end have "manipulated" the data.

Can anyone advise on a bulletproof solution?

Solution 1)The network traffic is logged with our request and responses.The only problem is that it should be connected to the data processing code, somehow, am I right?

Solution 2)?

Solution 3)

I use the Python requests package and make the following request to the API server:

import loggingdef getdata(timeinterval):    with requests.Session() as session:        logger.debug("request started")        parameters = {intervals:["Monthly"]}        headers = ..I also have an authorization token that I get from OAUTH2.        response = session.request("get",url,data=parameters,headers=headers)        response.raise_for_status()        api_logger.debug(f "request headers sent: {response.request.headers}")        api_logger.debug(f "response headers received: {response.headers}")        ds = response.json()        api_logger.info(f "response body received: {response.content})        return ds

If I use logging with the above parameters, I'm signing all files eletronically after closing the log file.Is this sufficient for an auditable solution? Is content "more safe" then text or should I apply raw format instead or is it make no difference at all?

Many thanks in advance!


Viewing all articles
Browse latest Browse all 3715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>