如何在没有API公钥的情况下发出API GET请求

时间:2017-12-31 22:11:43

标签: python-2.7 python-requests api-design

我正在尝试从API中提取数据但在文档中我只获得了一个API密钥,我假设它是私钥。

如果是这种情况,我如何在python中进行GET调用以根据以下文档文档(无法发布整个文档)提取数据,并且如果没有提供URL?:

Public Inventory API
 1.0 
[ Base url: https://partner-gateway.staging.mjplatform.com/v1] https://partners.mjfreeway.com/docs/inventory
API data related to inventory management

Schemes

catalog

GET
/catalog
Listing of Sellable Products
This request provides a detailed listing of all sellable products, also referred to throughout the system as "item masters", for the active facility. The listing can be filtered by some simple parameters.
Parameters
Name    Description
category_id
integer
(query) 
The ‘id’ of a single category to which you want to limit results
subcategory_id
integer
(query) 
The ‘id’ of a single subcategory to which you want to limit results
strain_id
integer
(query) 
The ‘id’ of a single strain to which you want to limit results
item_number
string
(query) 
The item number of a particular item master, i.e. BKSA00000003
uom_type
string
(query) 
The method of measurement for the item. Valid options are discrete, weight, and volume
available_online
boolean
(query) 
A boolean indicator of whether the item can be sold online

到目前为止,这是我的代码:

import requests

# api-endpoint
URL = "https://www.mjplatform.com/catalog"

# location given here
key = "123abc"

# defining a params dict for the parameters to be sent to the API
PARAMS = {URL:key}

# sending get request and saving the response as response object
r = requests.get(url = URL, params = PARAMS)

# extracting data in json format
data = r.json()

当我运行上述内容时,我收到以下消息:

ValueError: No JSON object could be decoded

如果我得到响应状态200,我不知道我在做什么来获取数据。

编辑:

Ran print(r.text)收到了这条消息:

<!DOCTYPE html><html lang="en"><head><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"><title>MJ Platform</title><link href="/main.b21e9284629fc8bfb7bc9b4158ad44b9.css" rel="stylesheet"></head><body><div id="defaultLoadingMessage"><div style="height:40px"></div><div class="col-md-4 col-md-offset-4"><div><h1 style="text-align:center">Loading MJ Platform</h1><div class="text-muted" style="text-align:center;width:600px;margin:auto;color:#aaa">If you continue to see this message for more than a few seconds, your browser is most likely out of date or incompatible. We support Chrome and Firefox. Other browsers may work but not provide an optimal experience. <strong>Safari and MS IE are specifically not supported.</strong></div></div></div></div><div id="app"></div><script type="text/javascript" src="/main.cccbe56cf819e9f8a6e3.js"></script></body></html>

如果我将信息拉入python anaconda窗口,浏览器怎么会过时?

1 个答案:

答案 0 :(得分:0)

提供的其他API信息未包含在文档中。

相关问题