首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django:_rowfactory中oracle/base.py中的“'int‘类型的参数是不可迭代的”

Django:_rowfactory中oracle/base.py中的“'int‘类型的参数是不可迭代的”
EN

Stack Overflow用户
提问于 2018-09-04 21:58:10
回答 1查看 232关注 0票数 1

我尝试将我的Django应用程序连接到Oracle DB,但查询结果异常:

代码语言:javascript
复制
TypeError: argument of type 'int' is not iterable

异常位置:_rowfactory中的/opt/isep/venv/lib/python3.4/site-packages/django/db/backends/oracle/base.py,第560行

代码语言:javascript
复制
def _rowfactory(row, cursor):
# Cast numeric values as the appropriate Python type based upon the
# cursor description, and convert strings to unicode.
casted = []
for value, desc in zip(row, cursor.description):
    if value is not None and desc[1] is Database.NUMBER:
        precision = desc[4] or 0
        scale = desc[5] or 0
        if scale == -127:
            if precision == 0:
                # NUMBER column: decimal-precision floating point
                # This will normally be an integer from a sequence,
                # but it could be a decimal value.
                if '.' in value:
                    value = decimal.Decimal(value)
                else:
                    value = int(value)
            else:
                # FLOAT column: binary-precision floating point.
                # This comes from FloatField columns.
                value = float(value)
        elif precision > 0:
            # NUMBER(p,s) column: decimal-precision fixed point.
            # This comes from IntField and DecimalField columns.
            if scale == 0:
                value = int(value)
            else:
                value = decimal.Decimal(value)
        elif '.' in value:
            # No type information. This normally comes from a
            # mathematical expression in the SELECT list. Guess int
            # or Decimal based on whether it has a decimal point.
            value = decimal.Decimal(value)
        else:
            value = int(value)
    elif desc[1] in (Database.STRING, Database.FIXED_CHAR,
                     Database.LONG_STRING):
        value = to_unicode(value)
    casted.append(value)
return tuple(casted)

由于value = 0if '.' in value:行出现错误。

我使用的是:Python3.4,Django1.11,cx_Oracle 6.0。

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-05 14:10:20

好的,我移除了我的venv,然后创建了另一个venv。这次我安装了Django 1.11.15和cx_Oracle 6.0。一切似乎都运行得很好。异常已消失。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52168027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档