json python调用git API

pcww981p  于 2023-03-09  发布在  Python
关注(0)|答案(2)|浏览(137)

我尝试通过Pipeline run的API调用将字符串传递给git page,但遇到一些字符串格式错误

gitCheckInputString = '''{"name":"''' + gitCheckName + '''","output":{"title":"''' + gitCheckName + '''","summary":"''' + message + '''","text":"''' + "The summary:\n{ unaudited: " + str($(params.unaudited)) + "\n    live: " + str($(params.live)) + "\n    real: " + str($(params.real)) + "  }" + "\n " + [Click on the link to see results on the Tekton build pipeline](''' + pipelineURL + ''') + '''"}}'''

print(gitCheckInputString)
SyntaxError: invalid syntax. Perhaps you forgot a comma?

预期输出为:

Click on the link to see results on the Tekton build

The summary: 

{ unaudited: 10
  
  live: 0
  
  real: 9
}
waxmsbnn

waxmsbnn1#

早上好朋友,看你的代码很复杂,一个字符串里面有很多项,很多(““),(“”),(“””“”),你尝试的这个引用我不明白。但是第一次看的时候,看起来像是你尝试传递一个字典或者一个json。我不确定是不是这样。但是就像你作为输出发布的例子一样,看起来你是想提个要求,我不确定。
好吧,我修正了它,一个例子法令:

gitString = {
    'name': 'gitCheckName',
    'output': {
        'title' : 'gitCheckName',
        'summary': 'message',
        'text': '',
        'The Summary': {
            'unaudited': '$(params.unaudited)',
            'live': '$(params.live)',            
        },
        'pielineURL': '',
    }
    
}

print(gitString)

结果:

{'name': 'gitCheckName', 'output': {'title': 'gitCheckName', 'summary': 'message', 'text': '', 'The Summary': {'unaudited': '$(params.unaudited)', 'live': '$(params.live)'}, 'pielineURL': ''}}

但是正如你所说,你正在尝试进行一个调用,如果是这样,你将不得不建立一个url,利用前面的dict与参数。
举个简单的例子:

component_1 = gitString['name']
component_2 = gitString['output']['title']

url = f'https://yourlink.com/{component_1}/{component_2}'
url

结果:
'https://yourlink.com/gitCheckName/gitCheckName'

x6yk4ghg

x6yk4ghg2#

“”““无效,不能像这样将两个字符串放在一起。
可能是一个逗号或者一个+。我不确定,因为我不太明白你想做什么。让你的代码更易读一点,我相信你自己会明白这个问题。像这样的大行不是一个好的做法。试着把它分开。
错误在这里:gitCheckName + '''","output"

相关问题