【问题标题】:jira - 401 Client Error: Unauthorized for urljira - 401 客户端错误:未经授权的 url
【发布时间】:2022-11-11 21:43:43
【问题描述】:

我正在创建一个 Slack 机器人来连接到 Jira。整个事情在我的本地机器上运行,但是,当我在 VM(Azure)上部署服务器时,它给了我这个错误。有什么想法吗? 错误:

401 Client Error: Unauthorized for url: https://***.atlassian.net/rest/api/2/search?startAt=0&fields=%2Aall&jql=project%3Dtest
2022-11-09 17:31:40,851 - ERROR - slack_bolt.App - Failed to run listener function (error: Object of type HTTPError is not JSON serializable)
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/slack_bolt/listener/thread_runner.py", line 120, in run_ack_function_asynchronously
    listener.run_ack_function(request=request, response=response)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/slack_bolt/listener/custom_listener.py", line 50, in run_ack_function
    return self.ack_function(
  File "/home/ubuntu/flask/src/helpers/slack_controller.py", line 87, in handle_jira_action
    sj_view_one(slack_app, body)
  File "/home/ubuntu/flask/src/helpers/slack_jira_services.py", line 41, in sj_view_one
    slack_app.client.views_open(trigger_id=body['trigger_id'], view={
  File "/home/ubuntu/.local/lib/python3.8/site-packages/slack_sdk/web/client.py", line 4452, in views_open
    return self.api_call("views.open", json=kwargs)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 156, in api_call
    return self._sync_send(api_url=api_url, req_args=req_args)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 187, in _sync_send
    return self._urllib_api_call(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 294, in _urllib_api_call
    response = self._perform_urllib_http_request(url=url, args=request_args)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 339, in _perform_urllib_http_request
    body = json.dumps(args["json"])
  File "/usr/lib/python3.8/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type HTTPError is not JSON serializable

【问题讨论】:

    标签: slack-api jira-rest-api confluence-rest-api


    【解决方案1】:

    经过数小时的研究,我找到了答案。这里有两个问题:

    第一,未经授权。 这是我在使用 Atlassian API 时遇到的问题。 (为它打开了一张票,但是,他们还不能帮助我)。

    第二,类型错误。 为了解决这个问题,一种方法是将异常错误映射到字符串。例如:

    try:
        something()
    exception Exception as error:
        logger.error(str(error))
        return str(error)
    

    我没有返回错误,而是发送了 str(error)。

    【讨论】:

      猜你喜欢
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2021-01-07
      • 2022-10-25
      • 1970-01-01
      • 2013-08-03
      • 1970-01-01
      相关资源
      最近更新 更多