我正在使用Python 2.7.10 64位。 在update_jira_field方法中,出现以下错误:
TypeError:post()至少接受1个参数(给定1个参数)
在将有效载荷声明为json的同时,我也尝试了requests.put()
和json = payload
的组合,但是仍然遇到相同的错误。
我不确定自己在做什么错,在使用请求模块时从未遇到此错误。
import requests
import json
import urllib2
auth = *****
propertKey = 'customfield_13557'
headers = {'Accept':'application/json','Bearer':****'}
def get_jira_real_id(jiraKey):
endpoint = 'https://****.atlassian.net/rest/api/3/issue/{0}'.format(jiraKey)
response = requests.get(endpoint, headers = headers, auth = auth)
if response.status_code == 200:
print "Success getting Jira Id"
response = json.loads(response.text)
return response['id']
def update_jira_field(jiraId,jiraKey):
endpoint = 'https://****.atlassian.net/rest/api/3/issue/{0}'.format(jiraId)
payload = dict({"fields": {"customfield_13557":{"self": "https://****.atlassian.net/rest/api/3/customFieldOption/14915", "value": "Yes", "id": "14915"}}})
response = requests.post(endpoint = endpoint, headers = headers, auth = auth, data = payload)
if response.status_code == 200:
print "Success! Updated", jiraId, jiraKey
jiraList = ['****']
for jiraKey in jiraList:
jiraId = get_jira_real_id(jiraKey)
update_jira_field(jiraId, jiraKey)
print "Done Done Done"
知道为什么会出现此错误吗?以及如何解决?
答案 0 :(得分:1)
您尝试传递名为endpoint
的命名参数,但正确的名称为url
。将行更改为
response = requests.post(endpoint, headers = headers, auth = auth, data = payload)