特殊字符“!”密码和用户名分别为“@”

2024-05-13 05:10:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图发送请求.post在Python中

username = "devoops123@mdf.nct.com"
password = "ChangemeinNv!"

我的剧本有

^{pr2}$

我在执行脚本时遇到了401 Authentication问题

在将密码作为参数传递给脚本时,我尝试了以下方法,但似乎没有任何帮助:

  • %21而不是!和{}代表@
  • 通过\转义两个特殊字符
  • 将参数括在" "

Tags: 方法脚本com密码authenticationusernamepasswordpost
1条回答
网友
1楼 · 发布于 2024-05-13 05:10:54

Jenkins希望您使用HTTP的Basic authentication特性发送用户名和密码。requests可以handle this natively。参见Jenkins Remove access API documentation

When your Jenkins is secured, you can use HTTP BASIC authentication to authenticate remote API requests.

只需将用户名和密码放入作为auth参数传入的元组中:

start_build_url = 'http://{0}/jenkins/job/{1}/job/{2}/buildWithParameters?token={3}&{4}'.format(
    jenkins_uri, folder_name, job_name, build_token, build_param)
r = requests.post(
    start_build_url, auth=(username, password),
)

无论是username还是{}值都不需要转义,让{}替您操心。在

相关问题 更多 >