Error with startswith Python

1

I am running a server written in python, and this error appears when I run it:

Traceback (most recent call last):
  File "desarrollo/open/server/bin/openerp-server.py", line 124, in <module>
    pooljobs=False)
  File "/home/daniel/desarrollo/open/server/bin/pooler.py", line 47, in get_db_and_pool
    pool.get('ir.actions.report.xml').register_all(cr)
  File "/home/daniel/desarrollo/open/server/bin/addons/base/ir/ir_actions.py", line 100, in register_all
    opj('addons',r['report_xml']),
  File "/usr/lib/python2.7/posixpath.py", line 75, in join
        if b.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'

I have python installed on 2 computers, with the same version and on one it works perfect, but on the other computer it does not.

I know that the startswith function works with strings, but I do not know why NoneType tells me when the on another computer runs correctly.

The error is exploiting with python itself:

/usr/lib/python2.7/posixpath.py not in the server files or modules, therefore the posixpath file can not be modified. I guess because it's the internal code of some python function

As you can see, I am using Ubuntu, 14.04, and the version of the python in 2.7.6 This is the same for both teams.

This is the code of register_all:

def register_all(self, cr):
    """Report registration handler that may be overridden by subclasses to
       add their own kinds of report services.
       Loads all reports with no manual loaders (auto==True) and
       registers the appropriate services to implement them.
    """
    opj = os.path.join
    cr.execute("SELECT * FROM ir_act_report_xml WHERE auto=%s ORDER BY id", (True,))
    result = cr.dictfetchall()
    svcs = netsvc.Service._services
    for r in result:
        print r['report_xml'] # NO puedo poner el print aquí porque me da error de identación... 
        if svcs.has_key('report.'+r['report_name']): #...con esta línea, pero no entiendo, pues está bien identado 
            continue
        if r['report_rml'] or r['report_rml_content_data']:
            report_sxw('report.'+r['report_name'], r['model'],
                    opj('addons',r['report_rml'] or '/'), header=r['header'])
        if r['report_xsl']:
            report_rml('report.'+r['report_name'], r['model'],
                    opj('addons',r['report_xml']),
                    r['report_xsl'] and opj('addons',r['report_xsl']))
        print r['report_xml'] # Aqui el print de depuracion no me da error 

Debugging with prints this function on both computers, the value r ['report_xml'] is sometimes none or it can be a path to an xml file. I suppose that when there is no xml the value is none. The issue is that with some value None of the machine that gives error, try to enter the attribute startswith.

The error I get in the first print is:

ir_actions.py:94:57: unindent does not match any outer indentation level
           if svcs.has_key('report.'+r['report_name']): # Y no comprendo...

I would like you to help me see what is, or what is not in this pc that does not work ...

Greetings

    
asked by DDBCDVD 14.11.2018 в 16:33
source

1 answer

1

The line where the error is jumping is 75% of /usr/lib/python2.7/posixpath.py . That is part of the posixpath.join() function, whose code is as follows:

def join(a, *p):
    """Join two or more pathname components, inserting '/' as needed.
    If any component is an absolute path, all previous path components
    will be discarded.  An empty last part will result in a path that
    ends with a separator."""
    path = a
    for b in p:
        if b.startswith('/'):
            path = b
        elif path == '' or path.endswith('/'):
            path +=  b
        else:
            path += '/' + b
    return path

The error 'NoneType' object has no attribute 'startswith' indicates that at that moment the variable b is worth None . Therefore, it has been passed as a parameter to the function join() some None .

Since according to the stacktrace you've shown this happens when this other line is executed (from your file /home/daniel/desarrollo/open/server/bin/addons/base/ir/ir_actions.py )

opj('addons',r['report_xml']),

I suspect that what is happening is that r['report_xml'] is None .

    
answered by 14.11.2018 / 17:12
source