dianping / cat

CAT 作为服务端项目基础组件,提供了 Java, C/C++, Node.js, Python, Go 等多语言客户端,已经在美团点评的基础架构中间件框架(MVC框架,RPC框架,数据库框架,缓存框架等,消息队列,配置系统等)深度集成,为美团点评各业务线提供系统丰富的性能指标、健康状况、实时告警等。
Apache License 2.0
18.69k stars 5.43k forks source link

python客户端无法连接服务端400 #2195

Closed wangketao2010 closed 2 years ago

wangketao2010 commented 2 years ago

版本:python 3.6

源代码如下: cat_test.py

!/usr/bin/python

import cat import time

print("hello world")

cat.init("my-xx-appkey",debug=True)

with cat.Transaction("foo", "bar") as t: try: print("try") t.add_data("a=1") cat.log_event("hook", "before")

do something

except Exception as e:
    print("ex")
    cat.log_exception(e)
finally:
    print("fin")
    cat.metric("api-count").count()
    cat.metric("api-duration").duration(100)
    cat.log_event("hook", "after")

time.sleep(1)


启动日志如下: hello world encoder: 1 sampling: 1 multiprocessing: 1 heartbeat: 0 Writing log to file /data/applogs/cat/cat_2022_04_08.log. File: "/tmp/ccat/src/lib/cat_clog.c", Line 103, in CLogInit 2022-04-08 20:03:24 [42844][[INFO] ] Cat log module has been successfully initialized. File: "/tmp/ccat/src/ccat/client_config.c", Line 127, in initCatClientConfig 2022-04-08 20:03:24 [42844][[INFO] ] Current hostname: hadoop163 File: "/tmp/ccat/src/ccat/message_manager.c", Line 83, in initMessageManager 2022-04-08 20:03:24 [42844][[INFO] ] Current ip: 192.168.0.163 File: "/tmp/ccat/src/ccat/message_manager.c", Line 94, in initMessageManager 2022-04-08 20:03:24 [42844][[INFO] ] Current ip hex: c0a857a3 File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 205, in getRouterFromServer 2022-04-08 20:03:24 [42844][[INFO] ] Start connect to router server 192.168.0.162 : 8000. File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 221, in getRouterFromServer 2022-04-08 20:03:24 [42844][[INFO] ] Connect to router server 192.168.0.162 : 8000 Success. File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 262, in getRouterFromServer 2022-04-08 20:03:24 [42844][[INFO] ] Got available server list: <!doctype html>HTTP Status 400 – Bad Request

HTTP Status 400 – Bad Request


Type Exception Report

Message The HTTP header line [host 192.168.0.162] does not conform to RFC 7230 and has been ignored.

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

Exception

java.lang.IllegalArgumentException: The HTTP header line [host 192.168.0.162] does not conform to RFC 7230 and has been ignored.
org.apache.coyote.
File: "/tmp/ccat/src/ccat/router_json_parser.c", Line 137, in parseCatJsonRouter
2022-04-08 20:03:24  [42844][[WARNING] ] CatRouter Json Parser Error before: [<!doctype html>HTTP Status 400 – Bad Request

HTTP Status 400 – Bad Request


Type Exception Report

Message The HTTP header line [host 192.168.0.162] does not conform to RFC 7230 and has been ignored.

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

Exception

java.lang.IllegalArgumentException: The HTTP header line [host 192.168.0.162] does not conform to RFC 7230 and has been ignored.
org.apac
File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 30, in updateCatServerConn
2022-04-08 20:03:24  [42844][[DEBUG] ] Get router from server successfully
File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 394, in updateCatServerConn
2022-04-08 20:03:24  [42844][[DEBUG] ] Trying connecting to the best server
File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 60, in tryConnBestServer
2022-04-08 20:03:24  [42844][[INFO] ] Try connect to server 127.0.0.1:2280.
File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 88, in tryConnBestServer
2022-04-08 20:03:24  [42844][[WARNING] ] Cannot connect to server 127.0.0.1:2280.
File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 60, in tryConnBestServer
2022-04-08 20:03:24  [42844][[INFO] ] Try connect to server 127.0.0.1:2280.
File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 88, in tryConnBestServer
2022-04-08 20:03:24  [42844][[WARNING] ] Cannot connect to server 127.0.0.1:2280.
File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 60, in tryConnBestServer
2022-04-08 20:03:24  [42844][[INFO] ] Try connect to server 127.0.0.1:2280.
File: "/tmp/ccat/src/ccat/server_connection_manager.c", Line 88, in tryConnBestServer
2022-04-08 20:03:24  [42844][[WARNING] ] Cannot connect to server 127.0.0.1:2280.
File: "/tmp/ccat/src/ccat/client.c", Line 0, in catClientInitInner
2022-04-08 20:03:24  [42844][[ERROR] ] Failed to initialize cat: Error occurred while getting router config from remote server.
File: "/tmp/ccat/src/ccat/client.c", Line 140, in catClientInitWithConfig
2022-04-08 20:03:24  [42844][[INFO] ] Cat has been initialized with appkey: my-xx-appkey
try
fin

感觉是报了 JSON反序列化异常,可能是编码有问题,所以客户端请求服务端 报 400了

power-lin commented 2 years ago

我这边没能复现你的场景,你应该是请求服务端路由时返回400错误码导致:

  1. 建议访问下服务端的页面,如127.0.0.1:8080/cat确认页面是否能正确展示
  2. 如果页面没问题,建议看下服务端的日志信息用于排查(如tomcat,nginx等)