英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论