You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用requests.post时出现TypeError: int is not callable错误求助

问题分析与解决方案

你的代码错误和分支判断逻辑无关,核心问题是调用日志方法时用错了语法:

  • logging.INFO和logging.ERROR是日志级别的常量(整数类型,比如INFO对应20),不是可执行的方法
  • 正确的日志调用应该用小写的方法名:logging.info()和logging.error()

修正后的代码

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

if response.status_code >= 300:
   logging.error(f"MY ERROR MESSAGE")
elif response.status_code < 300:
   logging.info(f"MY INFO MESSAGE")
else:
   logging.error(f"MY ERROR MESSAGE 2")

补充说明

你的状态码201确实是整数且满足<300的条件,之前的报错是因为尝试调用一个整数常量(logging.INFO)导致的,和分支逻辑无关。修正方法名的大小写后,代码会正常进入elif分支输出日志信息。

内容的提问来源于stack exchange,提问作者Daniel_T

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 00:15:30