Skip to content
Advertisement

Flask response.data raise error TypeError: ‘NoneType’ object is not callable

I use an online free api hoster and I have an issue with reponse.data, I use that on @app.after_request with should log path, args and server response, problem is that in console I get:

 GET /favicon.ico HTTP/1.1" 500 - Error on request: Traceback (most recent call last): File "D:Libsite-packageswerkzeugserving.py", line 319, in run_wsgi execute(self.server.app) File "D:Libsite-packageswerkzeugserving.py", line 308, in execute application_iter = app(environ, start_response) File "D:Libsite-packagesflaskapp.py", line 2095, in call return self.wsgi_app(environ, start_response) File "D:Libsite-packagesflaskapp.py", line 2084, in wsgi_app return response(environ, start_response) TypeError: 'NoneType' object is not callable

But on discord logger I see the log:

enter image description here

The code is :

def log(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        url = discord_link
        if dict(request.args) != {}:
            values = {
'username': 'Api-Logger',
'content': f'User called path:`{request.path}` with arsg: `{dict(request.args)}`'
    }
            result=external_requests.post(url, json = values)
            result.raise_for_status()
        return f(*args, **kwargs)
    return decorated_function


@app.after_request
@log
def after_request_func(response):
    try:
        SECURE.send_log(str(response.data).decode("utf-8"))
        return None
    except Exception as err:
        if isinstance(err, TypeError):
            pass
        else:
            SECURE.send_log(err)

I don’t know how to fix it But once I remove @app.after_request it works fine

Advertisement

Answer

I managed to solve the problem. The problem was that I was capturing the answer but not pushing further

FIXED:

@app.after_request
def after_request_func(response):
    SECURE.send_log((response.data).decode('utf-8'))
    return response
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement