Error module 'inspect' has no attribute 'getargspec'

Good afternoon.
I have the python version 3.11.7, making my api with flask
I need help to solve this problem:

[notice] A new release of pip is available: 23.2.1 → 23.3.2

Jan 9 03:37:59 PM[notice] To update, run: pip install --upgrade pip

Jan 9 03:38:00 PM==> Uploading build…

Jan 9 03:38:08 PM==> Build uploaded in 7s

Jan 9 03:38:08 PM==> Build successful :tada:

Jan 9 03:38:10 PM==> Deploying…

Jan 9 03:38:26 PM==> Using Node version 20.10.0 (default)

Jan 9 03:38:26 PM==> Docs on specifying a Node version: Setting Your Node.js Version | Render Docs

Jan 9 03:38:32 PM==> Running ‘gunicorn validcpf:app’

==> Using Node version 20.10.0 (default)

==> Docs on specifying a Node version: Setting Your Node.js Version | Render Docs

==> Running ‘gunicorn validcpf:app’

Error: module ‘inspect’ has no attribute ‘getargspec’

Hi,

A quick search for the error Error: module ‘inspect’ has no attribute ‘getargspec’ brings up many results.

It seems it may be related to the Python version. The current Render Python runtime defaults to 3.11.7 , where the getargspec attribute doesn’t exist: https://docs.python.org/3.11/library/inspect.html#inspect.getargspec

However, it does seem to exist in 3.10: https://docs.python.org/3.10/library/inspect.html#inspect.getargspec

There will always be differences between environments: development mode/Local, production mode/Render, etc. These differences need to be considered and configured as required for your own app in each environment.

Maybe start by ensuring the Python version is set to the same version you developed/tested on: https://render.com/docs/python-version

Alan

But in this case you would have to use getargs, right?

I’ll leave my code so you can take a look and see that I don’t use args

from flask import Flask, request, jsonify
from flask_cors import CORS

app = Flask(name)
CORS(app)

#Funçao para verificar os cpf
def valida_cpf(cpf):
# Remove caracteres não numericos do CPF
cpf = ‘’.join(filter(str.isdigit, cpf))

# Verifica se o CPF possui 11 digitos
if len(cpf) != 11:
    return False

# Calcula o primeiro digito verificador
soma = sum(int(cpf[i]) * (10 - i) for i in range(9))
digito1 = 11 - (soma % 11) if soma % 11 >= 2 else 0

# Calcula o segundo digito verificador
soma = sum(int(cpf[i]) * (11 - i) for i in range(10))
digito2 = 11 - (soma % 11) if soma % 11 >= 2 else 0

# Verifica se os digitos verificadores estão corretos
return int(cpf[9]) == digito1 and int(cpf[10]) == digito2

@app.route(‘/validar_cpf’, methods=[‘GET’])
def validar_cpf_rota():
# Obtém todos os parâmetros (GET ou POST) como um dicionário
params = request.values.to_dict()

# Obtém o valor do parâmetro 'cpf' do dicionário
cpf_param = params.get('cpf', '')

if valida_cpf(cpf_param):
    resultado = {'valido': True, 'mensagem': 'CPF válido'}
else:
    resultado = {'valido': False, 'mensagem': 'CPF inválido'}

return jsonify(resultado)

if name == ‘main’:
app.run(debug=True, port=8000)

General code debugging is beyond the scope of our support. Another community member may be able to assist further.

However, the original issue does look like a Python version issue when using Python > 3.10.

Alan

Sorry for the question, but I can’t find a solution for this, could you help me and tell me what I really need to do to achieve this? If you have a video showing the step by step that would be great. Thank you for your attention

The suggested solution is to use Python version less than 3.11 on Render. Preferably the same version you used to develop/test your app.

If this project works on your machine, confirm the Python version you have running, e.g.

$ python3 --version
Python 3.10.13

The command might be python --version, depending on your local setup.

Take the version number that your local Python outputs and set it as an environment variable on the “Environments” tab of your service, as per the docs:

  • Key: PYTHON_VERSION
  • Value: 3.10.13 (matching the one your local machine shows).

Alan

Thank you for the patience. Now it’s almost 100% hahaha. Now the website opens with a 404 error and the following message appears in the render

==> Detected service running on port 10000

==> Docs on specifying a port: Web Services | Render Docs

127.0.0.1 - - [12/Jan/2024:15:18:31 +0000] “GET / HTTP/1.1” 404 207 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36”

127.0.0.1 - - [12/Jan/2024:15:18:32 +0000] “GET /favicon.ico HTTP/1.1” 404 207 “https://testvalidate.onrender.com/” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36”

Does your code define a root path?

Alan

I put the default root route. The root route opened, but the endpoint is not opening, which would be ‘/validar_cpf’

==> Running ‘gunicorn validcpf:app’

Jan 12 02:10:03 PM[2024-01-12 17:10:03 +0000] [40] [INFO] Starting gunicorn 19.7.1

Jan 12 02:10:03 PM[2024-01-12 17:10:03 +0000] [40] [INFO] Listening at: http://0.0.0.0:10000 (40)

Jan 12 02:10:03 PM[2024-01-12 17:10:03 +0000] [40] [INFO] Using worker: sync

Jan 12 02:10:03 PM/opt/render/project/python/Python-3.10.13/lib/python3.10/os.py:1030: RuntimeWarning: line buffering (buffering=1) isn’t supported in binary mode, the default buffer size will be used

Jan 12 02:10:03 PM return io.open(fd, mode, buffering, encoding, *args, **kwargs)

Jan 12 02:10:03 PM[2024-01-12 17:10:03 +0000] [41] [INFO] Booting worker with pid: 41

Jan 12 02:10:12 PM127.0.0.1 - - [12/Jan/2024:17:10:12 +0000] “GET /validar_cpf HTTP/1.1” 200 48 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36”

https://testvalidate.onrender.com/validar_cpf returns a response from your code. If there’s an issue with that response, it will be a code issue that you’ll need to debug.

Alan

Hello, I’m here again, but now it’s another problem.
I did the right process and my api is now appearing to the uses, but when the uses are writing it always gives an error validation.
I’ll leave the logs here for you to take a look and check if there are any error logs, if there isn’t something in my code anyway.

==> Uploading build…

Jan 19 03:43:42 PM==> Build uploaded in 8s

Jan 19 03:43:42 PM==> Build successful :tada:

Jan 19 03:43:49 PM==> Deploying…

Jan 19 03:44:11 PM==> Using Node version 20.10.0 (default)

Jan 19 03:44:11 PM==> Docs on specifying a Node version: Setting Your Node.js Version | Render Docs

Jan 19 03:44:15 PMcp: cannot overwrite directory ‘/opt/render/project/src/.venv’ with non-directory

Jan 19 03:44:15 PM==> Running ‘gunicorn validcpf:app’

Jan 19 03:44:18 PM[2024-01-19 18:44:18 +0000] [42] [INFO] Starting gunicorn 19.7.1

Jan 19 03:44:18 PM[2024-01-19 18:44:18 +0000] [42] [INFO] Listening at: http://0.0.0.0:10000 (42)

Jan 19 03:44:18 PM[2024-01-19 18:44:18 +0000] [42] [INFO] Using worker: sync

Jan 19 03:44:18 PM/opt/render/project/python/Python-3.10.13/lib/python3.10/os.py:1030: RuntimeWarning: line buffering (buffering=1) isn’t supported in binary mode, the default buffer size will be used

Jan 19 03:44:18 PM return io.open(fd, mode, buffering, encoding, *args, **kwargs)

Jan 19 03:44:18 PM[2024-01-19 18:44:18 +0000] [43] [INFO] Booting worker with pid: 43

Jan 19 03:44:20 PMYour service is live :tada:

It looks like you might have created a .venv secret file which is creating the “cannot overwrite” error message in the logs you shared. But that doesn’t seem to be stopping the deploy. Try removing it to stop that message.

If you’re having an error while running your application, the error wouldn’t be in the deploy logs. If may be appearing in the service logs, the “Logs” tab of your service.

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.