Django-RQ API_TOKEN配置以访问统计端点。

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

Django-RQ API_TOKEN configuration to access to stats endpoint

问题

我正在尝试从django-rq队列中检索一些统计信息,但我在尝试访问Django-Rq文档中提供的URL时遇到了一些困难。

这些统计信息也可以以JSON格式通过/django-rq/stats.json获得,只有工作人员可以访问。如果您需要通过其他HTTP客户端(用于监视)访问此视图,您可以定义RQ_API_TOKEN并通过/django-rq/stats.json/<API_TOKEN>进行访问。

嗯,我已经在我的settings.py中定义了一个简单的RQ_API_TOKEN,仅用于测试目的。

RQ_API_TOKEN = "AAABBBCCC"

我尝试通过Postman访问它,但我不断收到以下响应:

{"error": true, "description": "在访问此视图之前,请在settings.py中配置API_TOKEN。"}

我尝试将令牌作为标头或甚至查询参数发送,但仍然无法按预期工作。

我尝试过的示例URLS(带有查询参数):

  • django-rq/stats.json/?token=AAABBBCCC
  • django-rq/stats.json/?api_token=AAABBBCCC
  • django-rq/stats.json/?API-TOKEN=AAABBBCCC
  • django-rq/stats.json/?API_TOKEN=AAABBBCCC

我也尝试了相同的操作,但没有查询参数,并将令牌插入为具有相同键的标头。什么都不起作用。

英文:

I'm trying to retrieve some statistics from the django-rq queues and I'm having some difficulties to access to the provided URL from the Django-Rq documentation

> These statistics are also available in JSON format via /django-rq/stats.json, which is accessible to staff members. If you need to access this view via other HTTP clients (for monitoring purposes), you can define RQ_API_TOKEN and access it via /django-rq/stats.json/<API_TOKEN>.

Well, I have defined a simple RQ_API_TOKEN just for testing purposes in my settings.py

RQ_API_TOKEN = &quot;AAABBBCCC&quot;

And I'm trying to access it via Postman but I keep receiving the following response:

> {&quot;error&quot;: true, &quot;description&quot;: &quot;Please configure API_TOKEN in settings.py before accessing this view.&quot;}

I've tried to send the token in the headers o even a query param, but it still doesn't work as is intended to work.

Example URLS that I've tried with query params:

  • django-rq/stats.json/?token=AAABBBCCC
  • django-rq/stats.json/?api_token=AAABBBCCC
  • django-rq/stats.json/?API-TOKEN=AAABBBCCC
  • django-rq/stats.json/?API_TOKEN=AAABBBCCC

The same I've tried, but leaving no query param and inserting the token as a header with the same keys. Nothing works.

答案1

得分: 0

"django-rq/stats.json/AAABBBCCC/"

有时候,最简单的事情就是正确的做法。

英文:

Well, it turns out that the correct URL to hit was:

django-rq/stats.json/AAABBBCCC/

Without any query param or header. Sometimes the simplest thing is the right thing to do.

huangapple
  • 本文由 发表于 2023年5月29日 19:54:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357140.html
匿名

发表评论

匿名网友

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

确定