简体   繁体   English

RavenPack API_key 在 postman 但不在 python 代码中工作

[英]RavenPack API_key is working in postman but NOT in python code

I am tryin to work with this repo https://github.com/RavenPack/python-api我正在尝试使用这个 repo https://github.com/RavenPack/python-api

Weirdly enough, the API is working perfectly with POSTMAN (it's a tool used to automate testing API development and HTTP calls)奇怪的是,API 与 POSTMAN 完美配合(它是一个用于自动化测试 API 开发和 Z29DC8666A24660F798 调用的工具)

Here's the code snippet这是代码片段

from ravenpackapi import RPApi
from ravenpackapi import Dataset

api = RPApi(
    api_key="_________" //correct api_key was intentionally removed for the post
)

ds = api.create_dataset(
    Dataset(
        name="New Dataset",
        filters={
            "relevance": {
                "$gte": 90
            }
        },
    )
)

print("Dataset created", ds)

Here is the error message.这是错误消息。

在此处输入图像描述

I repeat the same API key is working with postman on the same device and network.我重复相同的 API 密钥在同一设备和网络上与 postman 一起使用。 It's just that their python library is giving me a hard time.只是他们的 python 库让我很难过。

Exception has occurred: APIException
Got an error 401: body was '{"endpoint":"datasets","errors":[{"type":"UnauthorizedError","reason":"Unauthorized: Must supply a valid API key"}]}'
  File "C:\Users\XYZ\Documents\Python\RavenPackAPI.py", line 8, in <module>
    ds = api.create_dataset(

The issue may be that you are not pointing to the correct API cluster.问题可能是您没有指向正确的 API 集群。 The API Key may only be entitled to the previous product version. API 密钥可能仅有权使用以前的产品版本。

To point to the Edge cluster - set your API with the following code:要指向 Edge 集群 - 使用以下代码设置您的 API:

from ravenpackapi import RPApi

api = RPApi(product="edge")

https://github.com/RavenPack/python-api/blob/master/ravenpackapi/examples/create_dataset_edge.py https://github.com/RavenPack/python-api/blob/master/ravenpackapi/examples/create_dataset_edge.py

This code is the solution^^^ I was using an old code snippet that called the RPA cluster internally:此代码是解决方案^^^ 我使用的是内部调用 RPA 集群的旧代码片段:

from ravenpackapi import RPApi
from ravenpackapi import Dataset

#api = RPApi(api_key="L3KOJd7sjL7ZPsWXt4geSy")



api = RPApi(api_key="L3KOJd7sjL7ZPsWXt4geSy", product="edge")

ds = api.create_dataset(
    Dataset(
        **{
            "name": "Edge Dataset",
            "product": "edge",
            "product_version": "1.0",
            "frequency": "granular",
            "fields": [
                "timestamp_utc", "rp_document_id", "rp_entity_id", "entity_type", "entity_name",
                "country_code", "event_relevance", "entity_sentiment", "event_sentiment", "topic", "group"
            ],
            "filters": {
                "$and": [
                    {"event_relevance": {"$gte": 90}},
                    {"country_code": {"$in": ["GB"]}},
                    {"event_sentiment": {"$nbetween": [-0.5, 0.5]}}
                ]
            },
        }
    )
)

print("Dataset created", ds)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 请求与身份验证 (API_KEY) - Python request with authentication (API_KEY) Python kubernetes 模块没有属性“api_key” - Python kubernetes module has no attribute 'api_key' 错误:在 VS Code 桌面中未设置 API_KEY - Error: API_KEY not set in VS Code Desktop 存储api_key,api_pass - Storing an api_key, api_pass 类型错误:__init__() 缺少 1 个必需的位置参数:临时邮件 python 中的“api_key” - TypeError: __init__() missing 1 required positional argument: 'api_key' in temp-mail python 如何将字符串 p=“11.04GET /update?api_key=Q6YVHKEEEKA” 的前 4 个字符转换为在 python 中浮动? - How to convert first 4 characters of the string p=“11.04GET /update?api_key=Q6YVHKEEEKA” to float in python? GET api 请求在 POSTMAN 中有效,但在 python 代码中无效,我想将响应下载为 Z628CB5675FF524F3FEE7AAE91 - GET api request is working in POSTMAN but not in python code , I want to download the response as csv API 调用在 POSTMAN 中工作,但生成代码的 API 调用不起作用 - API Call is working in POSTMAN but API call with generated code is not working 使用api_key生成url并使用Tastypie生成slug(Django) - Generate url with api_key and slug with Tastypie (Django) 使用 Flask 通过 api_key POST 到 Elasticsearch 托管服务 - Using Flask to POST to Elasticsearch Hosted Service with api_key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM