背景 链接到标题 一直知道 Python 容易踩编码的坑,尤其是 Python2,昨天第一次遇到,记一下。
起因 链接到标题 产品中有一个账号关联的功能,需要的参数大概有 host,port,user,passwd 这么几个参数,昨天发现一个环境中账号关联失败,看请求应该还没到账号认证那里就失败了,查看 rest-server 日志,并没有发现错误异常,api 也是正常返回的,通过其他方式验证账号是有效的,当时觉得很奇怪,没什么想法。
调查 链接到标题 既然 rest-server 中日志没有报错,那么看看服务是否有什么异常。 这里特意说名下,如果服务使用的是 gunicorn 或者 celery 等第三方库作为守护进程,有一些系统报错是不会记录到你的服务中的,而是会直接打印到系统中(messages or systemd)。
发现 systemctl status 和 journal -u 有报错,报错内容如下:
4月 02 06:20:00 SCVM70 gunicorn[31225]: Traceback (most recent call last): 4月 02 06:20:00 SCVM70 gunicorn[31225]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 207, in _worker 4月 02 06:20:00 SCVM70 gunicorn[31225]: value = func(*args, **kwargs) 4月 02 06:20:00 SCVM70 gunicorn[31225]: error: getaddrinfo() argument 2 must be integer or string 4月 02 06:20:00 SCVM70 gunicorn[31225]: (<ThreadPool at 0x120ae50 0/5/10>, <built-in function getaddrinfo>) failed with error 字面意思是传递参数的类型不对,必须为 int 或者 string。