在JIRA中使用python创建测试周期时出现类型错误

问题描述 投票:0回答:1

我在计算机上安装了Zephyr和ZAPI插件,在本地安装了Jira核心。

我正在尝试使用以下代码创建新的测试周期,但出现以下错误

任何人都可以看看这个并提出应该怎么做。

from urllib.request import Request, urlopen
from json import dumps, load
from base64 import b64encode

import requests

username = '[email protected]'
password = 'qwerty'
projectId = 10001
versionId = ''
testsToAdd = ["test-2", "test-2"]


newCycleValues = dumps({
    "clonedCycleId": "",
    "name": "TestCycle-1.1-1",
    "build": "",
    "environment": "",
    "description": "Created In ZAPI",
    "startDate": "",
    "endDate": "",
    "projectId": projectId,
    "versionId": versionId
})


baseURL = 'http://localhost:8080'
createCycleURL = baseURL + '/rest/zapi/latest/cycle'
addTestsToCycleURL = baseURL + '/rest/zapi/latest/execution/addTestsToCycle/'



headers = {"Authorization": "Basic" + b64encode(username + ":" + password), "Content-Type": "application/json"}


print ("Creating new cycle...")

req = Request(createCycleURL, data=newCycleValues, headers=headers)

js_res = urlopen(req)

objResponse = load(js_res)
newCycleId = objResponse['id']

print ("New Cycle Created!")

print ("Adding test(s) to newly created cycle... \n")

addTestValues = dumps({
    "issues": testsToAdd,
    "versionId": versionId,
    "cycleId": newCycleId,
    "projectId": projectId,
    "method": "1"
})

request = Request(addTestsToCycleURL, data=addTestValues, headers=headers)
httpResponse = urlopen(request).read()

print ("HTTP RESPONSE:\n" + httpResponse + "\n")
print ("Test addition completed! \nPlease check HTTP RESPONSE above for confirmation of addition or for failure conditions.")

标题为headers = {"Authorization": " Basic " + b64encode(username + ":" + password), "Content-Type": "application/json"}

C:\Users\1728\demo\Scripts\python.exe C:/Users/1728/PycharmProjects/demo/localinstallofjira/createTestCycle.py
Traceback (most recent call last):
  File "C:/Users/1728/PycharmProjects/demo/localinstallofjira/createTestCycle.py", line 41, in <module>
    headers = {"Authorization": "Basic" + b64encode(username + ":" + password), "Content-Type": "application/json"}
  File "C:\Users\1728\AppData\Local\Programs\Python\Python38\lib\base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'str'

Process finished with exit code 1

标题为headers = {"Content-Type": "application/json"}

C:\Users\1728\demo\Scripts\python.exe C:/Users/1728/PycharmProjects/demo/localinstallofjira/createTestCycle.py
Traceback (most recent call last):
Creating new cycle...
  File "C:/Users/1728/PycharmProjects/demo/localinstallofjira/createTestCycle.py", line 51, in <module>
    js_res = urlopen(req)
  File "C:\Users\1728\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\1728\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 522, in open
    req = meth(req)
  File "C:\Users\1728\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1248, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

Process finished with exit code 1
python jira-rest-api python-jira jira-zephyr
1个回答
0
投票

与用户名一起使用访问令牌

© www.soinside.com 2019 - 2024. All rights reserved.