Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TypeError:在Python中_Python - Fatal编程技术网

TypeError:在Python中

TypeError:在Python中,python,Python,我有一个问题,函数返回一个数字。然后,当我尝试组装一个包含该号码的URL时,我遇到了失败 具体来说,我得到的错误是 TypeError:无法连接'str'和'NoneType'对象 不知道从这里到哪里去 以下是相关代码: # Get the raw ID number of the current configuration configurationID = generate_configurationID() # Update config name at in Cloud updateC

我有一个问题,函数返回一个数字。然后,当我尝试组装一个包含该号码的URL时,我遇到了失败

具体来说,我得到的错误是

TypeError:无法连接'str'和'NoneType'对象

不知道从这里到哪里去

以下是相关代码:

# 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中手动键入以下内容,它将非常有效

rest.rest(('put', http://myurl.com/configurations/123456?name=this_is_a_test_, myusername, mypassword))
我尝试了strconfigurationID,它吐回了一个数字,但我不再得到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$ 
您的配置ID为“无”。这可能意味着generate_configurationID没有返回值。在Python中,变量名无法丢失其值。在您发布的代码中,configurationID为None的唯一方法是generate_configurationID返回None,如果您不显式返回任何值,就会出现这种情况

但它会在屏幕上打印配置ID!你可以反对。当然可以,但这可能是在generate_configurationID中,您正在打印它以确保它是正确的,但忘记了返回它


您可以通过完整发布generate_configurationID来证明我的错误,我承认您的程序很神奇。

阅读错误消息。然后尝试一个最小的测试用例:hello+None-会发生什么?答案是你没有你不期望的东西,现在去找出在哪里/为什么。请更新标题,使其相关/有用。向我们展示:1。您对strConfiguration ID 2的尝试。baseURL 3。完整的错误信息,包括它抱怨的行号。我真的不知道今天还有什么其他方法。。。我不知道如何连接这些片段,我也不知道有什么地方不在这里。我确实读到了错误信息。我不明白为什么没有人能出现。定义了这些变量。什么是未定义的?我认为对象不能在Python中销毁。一旦定义,它们就被定义为持续时间。不是这样吗?
# 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