我有一個問題,函數返回一個數字。當我然後嘗試組裝一個包含該數字的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