OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Log REST API calls in Python

  • Thread starter Thread starter gale44
  • Start date Start date
G

gale44

Guest
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:

Code:
import logging

def 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!
<p>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.</p>
<p>Can anyone advise on a bulletproof solution?</p>
<p>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?</p>
<p>Solution 2)
?</p>
<p>Solution 3)</p>
<p>I use the Python requests package and make the following request to the API server:</p>
<pre><code>import logging

def 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
</code></pre>
<p>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?</p>
<p>Many thanks in advance!</p>
 

Latest posts

Online statistics

Members online
0
Guests online
6
Total visitors
6
Top