long() argument must be a string or a number, not 'list'

29 views
Skip to first unread message

Kimus

unread,
Jul 30, 2019, 2:12:26 PM7/30/19
to web2py-users
bem tenho o seguinte problema dessa vez, estou tentando criar a primeira tabela com relacionamento, só que não to conseguindo inserir nd dos dados na tabela pq ele fica dando esse erro "long() argument must be a string or a number, not 'list' 
meu controller 
@auth.requires_login()
def CadastroPropriedade():
formulario = db.PropriedadeRural.insert(area=request.vars.area)
return dict(mensagem=" ")
meu BD :
propriedadeRural = db.define_table('PropriedadeRural'
,Field('area','integer',label='Area de platação')
,Field('ano','date',label='ano da colheita')
,Field('lavoura','string',label='Tipo de cultivo')
,Field('producao','integer',label='Produção em sacos')
,Field('valorProducao','integer',label='Receita de Venda')
,Field('agricultor','references auth_user',label='Dono Da Lavoura'))

e o erro completo:

Número do Ticket

127.0.0.1.2019-07-30.12-01-32.d039c906-1e98-41a0-8ae5-e0657181b244

<type 'exceptions.TypeError'> long() argument must be a string or a number, not 'list'

Versão

web2py™Version 2.18.5-stable+timestamp.2019.04.08.04.22.03
PythonPython 2.7.15+: /usr/bin/python (prefix: /usr)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
Traceback (most recent call last):
File "/home/nti/Área de Trabalho/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/home/nti/Área de Trabalho/web2py/applications/ProjetoMargem/controllers/template.py", line 66, in <module>
File "/home/nti/Área de Trabalho/web2py/gluon/globals.py", line 421, in <lambda>
self._caller = lambda f: f()
File "/home/nti/Área de Trabalho/web2py/gluon/tools.py", line 3869, in f
return action(*a, **b)
File "/home/nti/Área de Trabalho/web2py/applications/ProjetoMargem/controllers/template.py", line 21, in CadastroPropriedade
formulario = db.PropriedadeRural.insert(area=request.vars.area)
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/objects.py", line 762, in insert
ret = self._db._adapter.insert(self, row.op_values())
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/adapters/base.py", line 480, in insert
query = self._insert(table, fields)
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/adapters/base.py", line 476, in _insert
','.join(self.expand(v, f.type) for f, v in fields))
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/adapters/base.py", line 476, in <genexpr>
','.join(self.expand(v, f.type) for f, v in fields))
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/adapters/base.py", line 445, in _expand
rv = self.represent(expression, field_type)
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/adapters/base.py", line 382, in represent
return super(SQLAdapter, self).represent(obj, field_type)
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/adapters/base.py", line 336, in represent
return self.representer.represent(obj, field_type)
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/representers/__init__.py", line 251, in represent
rv = self.get_representer_for_type(field_type)(rv, field_type)
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/representers/__init__.py", line 139, in __call__
return self.adapt(self.call(value, field_type))
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/representers/__init__.py", line 136, in _call
return self.inner_call(value)
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/representers/__init__.py", line 124, in _inner_call
return self.obj.f(self.representer, value, **kwargs)
File "/home/nti/Área de Trabalho/web2py/gluon/packages/dal/pydal/representers/base.py", line 30, in _integer
return str(long(value))
TypeError: long() argument must be a string or a number, not 'list'

Momento do Erro help

<type 'exceptions.TypeError'>(long() argument must be a string or a number, not 'list')


Dave S

unread,
Jul 30, 2019, 5:32:40 PM7/30/19
to web2py-users


Normally, request.vars.something is a string, and you should do a type conversion.  You didn't provide a sample URL for the request, so I'm guessing that your URL was something like my_app/my_controller/my_function?area=3,5 and the comma (',') turns one string into two, hence a list.

If that comma is a decimal point (which is true in many locale setttings), then you need to decide whether to use a dot (period, '.') instead, or have your borwwser translate to a dot via locale processing, or just deal with a list.  You still have to convert to a number

#
# for dots
#
area
= decimal(request.vars.area)

#
# for a "list"
#
x
, y = request.vars.area.split(',')
area
= decimal(x)/decimal(y)


Good luck!

/dps

Reply all
Reply to author
Forward
0 new messages