cm_api.api_client.ApiException: (error 404)

博客讲述遇到CDH问题,按https://blog.youkuaiyun.com/joomlaer/article/details/50073669处理仍出错,经多次复查,找到官方解决办法。通过访问cm地址http://host:port/api/version,找到CDH版本对应的api版本并修改version参数,最终解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一开始是这样遇到时,根据 https://blog.youkuaiyun.com/joomlaer/article/details/50073669 处理还是有错 

api = ApiResource(cm_host, cm_port, version=1, username="admin", password="***")

结果 

Traceback (most recent call last):
  File "hdfs.py", line 37, in <module>
    Test()
  File "hdfs.py", line 29, in Test
    result = api.query_timeseries(query, from_time, to_time)
  File "/usr/lib/python2.6/site-packages/cm_api/api_client.py", line 295, in query_timeseries
    return timeseries.query_timeseries(self, query, from_time, to_time, by_post=by_post)
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/timeseries.py", line 75, in query_timeseries
    ApiTimeSeriesResponse, True, params=params, data=data)
  File "/usr/lib/python2.6/site-packages/cm_api/endpoints/types.py", line 139, in call
    ret = method(path, params=params)
  File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 110, in get
    return self.invoke("GET", relpath, params)
  File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 73, in invoke
    headers=headers)
  File "/usr/lib/python2.6/site-packages/cm_api/http_client.py", line 183, in execute
    raise self._exc_class(ex)
cm_api.api_client.ApiException:  (error 404)

多次复查,找到官方解决方法

https://community.cloudera.com/t5/Cloudera-Manager-Installation/CM-Python-API/td-p/60338

访问的cm地址  http://host:port/api/version 

找到CDH版本所对应的api版本,修改version参数

api = ApiResource(cm_host, cm_port, version=12, username="admin", password="***")

搞定

``` from aylien_news_api import ApiClient, DefaultApi from aylien_news_api.configuration import Configuration import pandas as pd # 初始化API客户端 config = Configuration() config.api_key['X-AYLIEN-NewsAPI-Application-ID'] = "YOUR_APP_ID" config.api_key['X-AYLIEN-NewsAPI-Application-Key'] = "YOUR_APP_KEY" api_client = ApiClient(configuration=config) api = DefaultApi(api_client) # 搜索公司相关新闻(示例:Apple) params = { "text": "Apple Inc", "language": ["en"], "published_at_start": "NOW-1YEAR", "per_page": 100 } try: response = api.list_stories(**params) stories = response.stories # 提取关键字段并清洗 data = [] for story in stories: # 过滤无情感分析结果或低置信度的文章 if story.sentiment and story.sentiment.confidence >= 0.6: data.append({ "标题": story.title, "情感倾向": story.sentiment.polarity, "置信度": story.sentiment.confidence, "发布日期": story.published_at, "来源": story.source.name, "链接": story.links.permalink }) # 转换为DataFrame df = pd.DataFrame(data) # 去重(基于标题) df = df.drop_duplicates(subset=["标题"]) # 按情感分类并排序 df_sorted = df.sort_values(by=["情感倾向", "置信度"], ascending=[True, False]) # 保存为CSV df_sorted.to_csv("company_sentiment_analysis.csv", index=False, encoding="utf-8-sig") print("数据清洗完成,已保存到 company_sentiment_analysis.csv") except Exception as e: print("API调用或数据处理失败:", e)```把这段代码中错误地方提取出来
03-26
ERROR: Exception in ASGI application + Exception Group Traceback (most recent call last): | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 76, in collapse_excgroups | yield | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 177, in __call__ | async with anyio.create_task_group() as task_group: | ^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__ | raise BaseExceptionGroup( | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi | result = await app( # type: ignore[func-returns-value] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ | return await self.app(scope, receive, send) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__ | await super().__call__(scope, receive, send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/applications.py", line 112, in __call__ | await self.middleware_stack(scope, receive, send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187, in __call__ | raise exc | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in __call__ | await self.app(scope, receive, _send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85, in __call__ | await self.app(scope, receive, send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 176, in __call__ | with recv_stream, send_stream, collapse_excgroups(): | ^^^^^^^^^^^^^^^^^^^^ | File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 158, in __exit__ | self.gen.throw(value) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 82, in collapse_excgroups | raise exc | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 178, in __call__ | response = await self.dispatch_func(request, call_next) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/06.renwu/00.fix_bug/test-automation-platform-backend/src/app/middlewares/request_logger_middleware.py", line 17, in dispatch | response = await call_next(request) | ^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 156, in call_next | raise app_exc | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 141, in coro | await self.app(scope, receive_or_disconnect, send_no_error) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ | await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app | raise exc | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app | await app(scope, receive, sender) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 714, in __call__ | await self.middleware_stack(scope, receive, send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 734, in app | await route.handle(scope, receive, send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 288, in handle | await self.app(scope, receive, send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 76, in app | await wrap_app_handling_exceptions(app, request)(scope, receive, send) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app | raise exc | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app | await app(scope, receive, sender) | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 73, in app | response = await f(request) | ^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 301, in app | raw_response = await run_endpoint_function( | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 212, in run_endpoint_function | return await dependant.call(**values) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/06.renwu/00.fix_bug/test-automation-platform-backend/src/app/api/v1/device_monitor.py", line 281, in get_memory_trend | resp_memory = await influxdb.query_api.query(query_mem_trend) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/influxdb_client/client/query_api_async.py", line 102, in query | response = await self._post_query(org=org, query=self._create_query(query, self.default_dialect, params)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/influxdb_client/client/query_api_async.py", line 234, in _post_query | raise ApiException(http_resp=RESTResponseAsync(response, data)) | influxdb_client.rest.ApiException: (401) | Reason: Unauthorized | HTTP response headers: <CIMultiDictProxy('Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.7.12', 'X-Platform-Error-Code': 'unauthorized', 'Date': 'Wed, 13 Aug 2025 06:30:57 GMT', 'Content-Length': '55')> | HTTP response body: b'{"code":"unauthorized","message":"unauthorized access"}' | +------------------------------------ During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__ await super().__call__(scope, receive, send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/applications.py", line 112, in __call__ await self.middleware_stack(scope, receive, send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187, in __call__ raise exc File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in __call__ await self.app(scope, receive, _send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85, in __call__ await self.app(scope, receive, send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 176, in __call__ with recv_stream, send_stream, collapse_excgroups(): ^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 158, in __exit__ self.gen.throw(value) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 82, in collapse_excgroups raise exc File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 178, in __call__ response = await self.dispatch_func(request, call_next) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/06.renwu/00.fix_bug/test-automation-platform-backend/src/app/middlewares/request_logger_middleware.py", line 17, in dispatch response = await call_next(request) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 156, in call_next raise app_exc File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 141, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app raise exc File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app await app(scope, receive, sender) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 714, in __call__ await self.middleware_stack(scope, receive, send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 734, in app await route.handle(scope, receive, send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 288, in handle await self.app(scope, receive, send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 76, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app raise exc File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app await app(scope, receive, sender) File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 73, in app response = await f(request) ^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 301, in app raw_response = await run_endpoint_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 212, in run_endpoint_function return await dependant.call(**values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/06.renwu/00.fix_bug/test-automation-platform-backend/src/app/api/v1/device_monitor.py", line 281, in get_memory_trend resp_memory = await influxdb.query_api.query(query_mem_trend) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/influxdb_client/client/query_api_async.py", line 102, in query response = await self._post_query(org=org, query=self._create_query(query, self.default_dialect, params)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/qxz5mik/platform_work/04.code/test-automation-platform-backend/.venv/lib/python3.12/site-packages/influxdb_client/client/query_api_async.py", line 234, in _post_query raise ApiException(http_resp=RESTResponseAsync(response, data)) influxdb_client.rest.ApiException: (401) Reason: Unauthorized HTTP response headers: <CIMultiDictProxy('Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.7.12', 'X-Platform-Error-Code': 'unauthorized', 'Date': 'Wed, 13 Aug 2025 06:30:57 GMT', 'Content-Length': '55')> HTTP response body: b'{"code":"unauthorized","message":"unauthorized access"}' 这是什么错误,如何解决
最新发布
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值