[英]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.