Python AttributeError: 'NoneType' 对象没有属性 'endswith'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17772908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AttributeError: 'NoneType' object has no attribute 'endswith'
提问by mr.G
I am currently working on a Python script that updates a web page. But running the main script generates this error:
我目前正在开发一个更新网页的 Python 脚本。但是运行主脚本会产生这个错误:
<res status='-1'><error message="'NoneType' object has no attribute 'endswith'"><![CDATA[
Traceback (most recent call last):
File "/path/to/file/ws_config.py", line XXXX, in Run
tests = TestList().tests
File "/path/to/file/ws_config.py", line XXXX, in __init__
UpdateTestGroup(None),
File "/path/to/file/ws_config.py", line XXXX, in __init__
test = CT.CurlTest(settings),
File "/path/to/file/config_tests.py", line XXXX, in __init__
self.params.path = os.path.join('/', os.path.join(params.dir, params.file))
File "/usr/lib/python2.6/posixpath.py", line 67, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
I cannot past any code because is too long. What I am trying to understand is where the error lays or what part of the code is triggering the AttributeError. Can you please help me???
我无法通过任何代码,因为太长了。我想了解的是错误所在或代码的哪一部分触发了 AttributeError。你能帮我么???
采纳答案by zhangyangyu
The path
in the elif
is a None
and None == ''
returns False
so the remain will be executed. And backwards, the params.dir
is a None
. You need to check your code where the params.dir
generated to see how the None
come.
在path
在elif
是None
和None == ''
回报False
,因此仍然会被执行。反过来,params.dir
是一个None
. 你需要检查你的代码在哪里params.dir
生成,看看是怎么None
来的。