我有一个问题,函数返回一个数字。当我然后尝试组装一个包含该数字的URL时,我遇到了失败。TypeError:在Python中
具体来说,我得到的错误是
TypeError: cannot concatenate 'str' and 'NoneType' objects
不知道在哪里可以从这里走。
下面是相关的代码:
# Get the raw ID number of the current configuration
configurationID = generate_configurationID()
# Update config name at in Cloud
updateConfigLog = open(logBase+'change_config_name_log.xml', 'w')
# Redirect stdout to file
sys.stdout = updateConfigLog
rest.rest(('put', baseURL+'configurations/'+configurationID+'?name=this_is_a_test_', user, token))
sys.stdout = sys.__stdout__
它完美如果我手动键入以下
rest.rest(('put', http://myurl.com/configurations/123456?name=this_is_a_test_, myusername, mypassword))
我试图str(configurationID)
和rest.rest()它吐出回号码,但我不再获得URL的其余部分...
想法?帮帮我?
好的......为了显示我的baseURL和我的配置ID,这里是我所做的。
print 'baseURL: '+baseURL
print 'configurationID: '+configurationID
这里是我回来
it-tone:trunk USER$ ./skynet.py fresh
baseURL: https://myurl.com/
369596
Traceback (most recent call last):
File "./skynet.py", line 173, in <module>
main()
File "./skynet.py", line 30, in main
fresh()
File "./skynet.py", line 162, in fresh
updateConfiguration()
File "./skynet.py", line 78, in updateConfiguration
print 'configurationID: '+configurationID
TypeError: cannot concatenate 'str' and 'NoneType' objects
it-tone:trunk USER$
什么有趣的是,我是,369596是配置ID,但是像以前好像揍一切叫了起来周围。
正如下面指出的,我的generate_configurationID不是返回值的值,而是它正在打印它。
# from generate_configurationID
def generate_configurationID():
dom = parse(logBase+'provision_template_log.xml')
name = dom.getElementsByTagName('id')
p = name[0].firstChild.nodeValue
print p
return p
**阅读错误信息**然后尝试一个最小的测试用例:'“hello”+ None' - 会发生什么?答案是“你有没有你不期待的地方”(现在去找出地方/为什么)。请更新标题以使其相关/有用。 – 2012-04-23 19:49:23
向我们展示:1.您尝试'str(configurationID)'2. baseURL 3.完整的错误信息,包括它所抱怨的行号。 – 2012-04-23 19:51:28
我真的不知道该如何去做这件事......我不知道如何连接这些作品,而我也不知道该怎么办。我确实看过错误信息。我不明白“没有”甚至可以出现。这些变量被定义。什么未定义他们?我认为对象不能在Python中销毁。一旦定义,他们就定义了持续时间。不是这样吗? – TheWellington 2012-04-23 20:25:09