【问题标题】:Requests.post error| TypeError: post() takes at least 1 argument (1 given)Requests.post 错误| TypeError: post() 至少需要 1 个参数(给定 1 个)
【发布时间】:2018-11-18 09:44:02
【问题描述】:

我正在使用 Python 2.7.10 64 位。 在 update_jira_field 方法中,我收到以下错误:

TypeError: post() 至少需要 1 个参数(给定 1 个)

我也尝试了requests.put()json = payload 的组合,同时将有效负载声明为 json,但仍然遇到相同的错误。

我不确定自己做错了什么,在使用请求模块时从未遇到过此错误。

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"

知道为什么会出现此错误吗?以及如何解决?

【问题讨论】:

    标签: python python-requests typeerror jira-rest-api


    【解决方案1】:

    您尝试传入一个名为endpoint 的命名参数,但正确的名称是url。如果您将行更改为

    ,它会起作用
    response = requests.post(endpoint, headers = headers, auth = auth, data = payload)
    

    【讨论】:

      猜你喜欢
      • 2012-10-08
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多