我想知道,为什么我得到"对于带有基数10错误"的int()无效的文字?但在交互模式下工作得很好吗?
fees = {u'nid':u'179', u'type':u'fees', u'jamb_no': u'01234SS'}
for fee in fees:
# Transaction model
try:
txn = Transaction()
txn.nid = int(fee.get(u'nid'))
txn.type = options.get(u'type')
txn.jamb_no = fee.get(u'jamb_no') # invalid literal for int() with base 10
txn.save()
class Transaction(models.Model):
id = models.AutoField(primary_key=True)
type = models.CharField(max_length=50)
nid = models.IntegerField()
jamb_no = models.CharField(max_length=20, blank=False)
回溯:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\celery-2.3.2-py2.7.egg\celery\execute\trace.py"
, line 36, in trace
return cls(states.SUCCESS, retval=fun(*args, **kwargs))
File "C:\Python27\lib\site-packages\celery-2.3.2-py2.7.egg\celery\app\task\__init__
.py", line 232, in __call__
return self.run(*args, **kwargs)
File "C:\Python27\lib\site-packages\celery-2.3.2-py2.7.egg\celery\app\__init__.py",
line 172, in run
return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\transaction.py",
line 217, in inner
res = func(*args, **kwargs)
File "api\tasks.py", line 142, in queue_transaction
ValueError: invalid literal for int() with base 10: '01234SS'
在交互式提示符上,这很好用
>>> fees = {u'jamb_no': u'01234SS'}
>>> fees.get(u'jamb_no')
u'01234SS'
>>>
>>> jamb_no = u'01234SS'
>>> str(jamb_no)
'01234SS'
请帮帮我。我已经在这2天了。
答案 0 :(得分:0)
这个问题与芹菜有关。当我对tasks.py进行更改时,需要重新启动芹菜。我没有这样做,这显然导致重复的错误消息,即使状态已经改变。