dateTime.dateTime.utcnow()随机设置7天

发布于 2025-01-24 11:45:08 字数 765 浏览 5 评论 0原文

我有一个问题,我无法弄清楚如何解决。

我有一个python脚本,基本上是用tweepy查询Twitter API。

一切正常,但是随机地我得到了一个400个不良请求错误,这是由于错误的参数引起的。所讨论的参数是start_time,我使用它将搜索限制在最后60秒(此脚本不断运行,每5秒进行一次查询)。

因此,该参数是这样计算的:

datetime.datetime.utcnow() - datetime.timedelta(seconds=60)

正如我所说的那样,它有99.9%的时间,但偶尔会在一周前跳跃。例如

​ 无效的“ start_time”:'2022-04-18T23:31Z'。 “ start_time”必须在2022-04-18t23:31z之后或之后,

好像服务器从2022-04-25随机移动到2022-04-18,

这使所有难以解决的问题是此脚本作为服务运行。如果我停下来开始服务,而无需在所有服务器日期触摸时,一切都按预期工作。

在24h 7/7服务运行的两个多月份,我遇到了这个错误。

我该怎么做才能解决此错误?它是随机的。

一个快速解决方案可能是处理例外,我会这样做

except tweepy.errors.HTTPException as e:
            print(e)
            return('error')

,但在这种情况下,我不知道如何关闭和重新启动该服务。

有帮助吗?

I have an issue I can't figure how to fix.

I have a python script that basically query twitter api with tweepy.

Everything works fine but randomly I got a 400 bad request error caused by a wrong parameter. The parameter in question is start_time, I use it to limit the search to the last 60 seconds (this script runs constantly and do a query every 5 seconds).

So the parameter is calculated like this:

datetime.datetime.utcnow() - datetime.timedelta(seconds=60)

As I said it works 99,9% of the time, but occasionally it jump one week back. So for instance if I have a look at the log, I can see that there is a query at 2022-04-25T23:29:40.000Z and the following with an error

400 Bad Request
Invalid 'start_time':'2022-04-18T23:31Z'. 'start_time' must be on or after 2022-04-18T23:31Z

As if the server randomly moved from 2022-04-25 back to 2022-04-18

What it makes everything hard to troubleshoot is that this script runs as a service. If I do a stop and start of the service, without touching at all the server date, everything works as expected.

I encountered this error maybe a couple of time in more than two months of 24h 7/7 service run.

What can I do to troubleshoot this error? It is random.

A quick fix could be to handle the exception, I do that with

except tweepy.errors.HTTPException as e:
            print(e)
            return('error')

But I don't know how to close and restart the service in this case.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文