我有一段代码使用我想使用由Аrtifactory(语言:python)提供的REST API更新repo配置这里是函数的代码:
def extractExtConfig(handle,repoUrl):
'''
Extract external repos configuration. We are specifically interested in :
1. If the repo is blackedout or not
2. Online/Offline`enter code here` status
'''
extRepos=simplejson.load(handle)
#print extRepos
#print isinstance(extRepos,dict)
#If repo is blackedout, we skip it
if extRepos['blackedOut']:
print 'blackedout'
#if repo is offline, we check if its accessibe
#if it's accessible, we make bring it online
if extRepos['offline']:
print extRepos['url']+' is offline'
try:
urllib2.urlopen(extRepos['url'])
except urllib2.URLError,e:
print str(e)
pass
except:
#print Exception
pass
else:
print 'Here we switch status'
print extRepos
#newData=simplejson.dump({'offline': 'false'})
extRepos['offline']='False'
newData=simplejson.dumps(extRepos)
print newData
print repoUrl
#test here
req=urllib2.Request(repoUrl,newData,{'Content-Type': 'application/json'})
handleNew=urllib2.urlopen(req)
response=handleNew.read()
print response
req2=urllib2.Request(repoUrl)
handlenew2=urllib2.urlopen(req2)
test=simplejson.load(handlenew2)
print test
#pass
else:
print extRepos['url']+' is onlne'
pass
因此,在我执行我的代码后,它运行良好,我收到一条响应,说明配置已更新。但是当我打印上面的测试值时,它会显示 repo 的旧配置值。当我从前端检查时,我看到了相同的一组值。有人可以帮我找到我在这里缺少的东西。可能是我的 post 请求语法搞砸了!!!