有办法通过PRAW跟踪API调用吗?

huangapple go评论65阅读模式
英文:

Is there a way to track API calls through PRAW?

问题

我正在使用PRAW在我的Python脚本中,并尝试找出一种方法来跟踪它所进行的API调用次数。是否有办法做到这一点?

致敬。

英文:

I'm using [PRAW](https://praw.readthedocs.io/en/stable/index.html "The Python Reddit API Wrapper") in my Python script and am trying to figure out a way to track the number of API calls that it has made. Is there a way to do this?

Regards.

答案1

得分: 1

你可以在PRAW中启用日志记录:https://praw.readthedocs.io/en/stable/getting_started/logging.html

从该页面中:

> 当正确配置时,发出的HTTP请求应产生类似以下的输出:
>
> 获取:GET https://oauth.reddit.com/api/v1/me
> 数据:无
> 参数:{'raw_json': 1}
> 响应:200(876字节)
>
> 此外,处理POST操作引发的任何API速率限制将生成类似以下消息的日志条目:
>
> 触发速率限制,休眠5.5秒

你可以最简单地在日志中使用grep -c来查找Fetching。当然,你也可以将你的应用程序连接到更复杂的监控工具。

英文:

You can enable logging in PRAW : https://praw.readthedocs.io/en/stable/getting_started/logging.html

From that page:

> When properly configured, HTTP requests that are issued should produce
> output similar to the following:
>
> Fetching: GET https://oauth.reddit.com/api/v1/me
> Data: None
> Params: {'raw_json': 1}
> Response: 200 (876 bytes)
>
> Furthermore, any API ratelimits from POST actions that are handled
> will produce a log entry with a message similar to the following
> message:
>
> Rate limit hit, sleeping for 5.5 seconds

Simplest thing you could do is just grep -c over the log looking for Fetching. Or, of course, wire your application to more sophisticated monitoring tools.

huangapple
  • 本文由 发表于 2023年6月22日 15:24:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76529477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定