如何用python对clickup进行评论?

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

我想在 clickup 中评论特定任务,但它响应 401 错误。

url = "https://api.clickup.com/api/v2/task/861m8wtw3/comment"

headers = {
    "Authorization": "Bearer <my api key>",
    "Content-Type": "application/json"
}

# comment = input('Type your comment text: \n')
comment = 'test comment'

data = {
    "content": f"{comment}"
}

response = requests.post(url, headers=headers, json=data)

输出为:

<Response [401]>

有什么问题吗?

我尝试添加 mozilla 标头作为用户代理密钥:

'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'

但仍然收到 401 错误!

python api python-requests clickup-api
2个回答
0
投票

问题似乎出在 Authorization 标头上。确保标头仅包含 API token 字符串,前面没有“Bearer”。像这样:

headers = {
    "Authorization": "<your api token>",
    "Content-Type": "application/json"
}

0
投票

问题在于 headersdata

    headers = {
    "Authorization": "<your api token>",
    "Content-Type": "application/json",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
    }

    # comment = input('Type your comment text: \n')
    comment = 'test comment'

    data = {
        "comment_text": f"{comment}"
    }

使用这种格式,我能够成功发布到 ClickUp 任务。

  1. 正如其他人提到的,

    Authorization
    不应该以Bearer开头,而应该只是
    API key

    "Authorization": "<your api token>"
    
  2. User-Agent
    可以出现在标头中,但请求可以在没有它的情况下工作。

  3. data
    中,您使用
    content
    发布评论。使用你的方法,我返回了 401 错误。

    Failed to post comment: 401
    {'err': 'Comment is required', 'ECODE': 'OAUTH_062'}
    

    相反,您应该使用

    comment_text
    ,这是 ClickUp 期望的字段。

     data = {
         "comment_text": f"{comment}"
     }
    
© www.soinside.com 2019 - 2024. All rights reserved.