我试图使用BlueJeans API来创建一个客户端应用程序,https://github.com/bluejeans/api-rest-meetings/blob/master/libs/python/docs/ApplicationApi.md#create_client_application.我已经获得了一个客户端ID和秘密以及用户ID,并将它们保存在我的Django设置中。我还编写了一个函数来获取访问令牌:
import json
from urllib.parse import urljoin
import requests
import logging
import BlueJeansMeetingsRestApi
from django.conf import settings
from rest_framework import status
logger = logging.getLogger(__name__)
class ConferenceScheduler(object):
BASE_URL = 'https://api.bluejeans.com'
@staticmethod
def get_token():
# Obtain an access token to initiate a session with BlueJeans
# (We use the Client Grant Type which grants us enterprise-level access)
response = requests.post(
url=urljoin(base=ConferenceScheduler.BASE_URL, url='/oauth2/token'),
json={
'grant_type': 'client_credentials',
'client_id': settings.BLUEJEANS_KEY,
'client_secret': settings.BLUEJEANS_SECRET})
if response.status_code == status.HTTP_200_OK:
return json.loads(response.content).get('access_token')
else:
logger.error(f"A request for a BlueJeans access token returned a non-200 response.\n"
f"Status code: {response.status_code}\n"
f"Reason: {response.reason}")
继续在Django shell中,我试图遵循示例中的步骤,但是我得到了一个ApiExcema
:
In [1]: from lucy_web.lib.conferencing import *
In [2]: BlueJeansMeetingsRestApi.configuration.api_key['access_token'] = ConferenceSch
...: eduler.get_token()
In [3]: api_instance = BlueJeansMeetingsRestApi.ApplicationApi()
In [4]: user_id = settings.BLUEJEANS_USER_ID
In [6]: application = BlueJeansMeetingsRestApi.Application()
In [7]: api_response = api_instance.create_client_application(user_id, application)
---------------------------------------------------------------------------
ApiException Traceback (most recent call last)
<ipython-input-7-1bf90ba9e2a8> in <module>()
----> 1 api_response = api_instance.create_client_application(user_id, application)
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/apis/application_api.py in create_client_application(self, user_id, application, **kwargs)
65 return self.create_client_application_with_http_info(user_id, application, **kwargs)
66 else:
---> 67 (data) = self.create_client_application_with_http_info(user_id, application, **kwargs)
68 return data
69
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/apis/application_api.py in create_client_application_with_http_info(self, user_id, application, **kwargs)
148 _preload_content=params.get('_preload_content', True),
149 _request_timeout=params.get('_request_timeout'),
--> 150 collection_formats=collection_formats)
151
152 def regenerate_client_application_secret(self, user_id, client_id, **kwargs):
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, callback, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
324 body, post_params, files,
325 response_type, auth_settings, callback,
--> 326 _return_http_data_only, collection_formats, _preload_content, _request_timeout)
327 else:
328 thread = threading.Thread(target=self.__call_api,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in __call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, callback, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
151 post_params=post_params, body=body,
152 _preload_content=_preload_content,
--> 153 _request_timeout=_request_timeout)
154
155 self.last_response = response_data
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in request(self, method, url, query_params, headers, post_params, body, _preload_content, _request_timeout)
369 _preload_content=_preload_content,
370 _request_timeout=_request_timeout,
--> 371 body=body)
372 elif method == "PUT":
373 return self.rest_client.PUT(url,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/rest.py in POST(self, url, headers, query_params, post_params, body, _preload_content, _request_timeout)
261 _preload_content=_preload_content,
262 _request_timeout=_request_timeout,
--> 263 body=body)
264
265 def PUT(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/rest.py in request(self, method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)
217
218 if not 200 <= r.status <= 299:
--> 219 raise ApiException(http_resp=r)
220
221 return r
ApiException: (415)
Reason: Unsupported Media Type
HTTP response headers: HTTPHeaderDict({'Server': 'BlueJeans Proxy', 'Date': 'Fri, 06 Jul 2018 22:17:24 GMT', 'X-NewRelic-App-Data': 'PxQAV1ZaABADUVZbBAACU0YdFGQHBDcQUQxLA1tMXV1dORYyVBNFDgFCa04tBkFoRB0RBwpSWAtKU1pGBwwGA14RFhFdSkJbUABKT10IVQcHT1QNA010WlYBAhtUXVIlC19CUgsIBhAcQlkMVldAU0cMVg8MOl0NClNqPERPCB0ASFFMBwMBU1UCAAZRSlNOEgYLWgAAVwMEXQoAUlUCAVAUag==', 'X-Trace-Token': 'sj1-prod-cobalt-03-158215204', 'Content-Type': 'application/json; charset=UTF-8', 'Content-Length': '47'})
HTTP response body: {"code":415,"message":"Unsupported Media Type"}
我不明白这里可能有什么问题,因为user_id
被指定为留档中的整数。如何从此终结点获得有效响应?
最新消息
我还尝试发出一个“普通”请求,其头部包含访问令牌,如python请求与身份验证(access_令牌)中所述。但是,在这种情况下,我得到了401
(未经授权)响应:
In [9]: BASE_URL = ConferenceScheduler.BASE_URL
In [10]: BASE_URL
Out[10]: 'https://api.bluejeans.com'
In [11]: url = urljoin(BASE_URL, f'/v1/user/{settings.BLUEJEANS_USER_ID}')
In [13]: session = requests.Session()
In [14]: token = ConferenceScheduler.get_token()
In [15]: session.headers.update({'Authorization': f'access_token {token}'})
In [16]: response = session.get(url)
In [17]: response.status_code
Out[17]: 401
In [19]: response.reason
Out[19]: 'Unauthorized'
通过此API调用检查,我的令牌仍然有效:
In [22]: response = requests.get(urljoin(BASE_URL, '/oauth2/tokenInfo'), params={'access_token': token}
...: )
In [23]: response.status_code
Out[23]: 200
所以一个额外的问题是:我如何使用请求
而不是BlueJeansMeetingsRestApi
来发出请求?
通常,当您忽略http头:Content-Type:application/json时,会出现415不支持的媒体类型错误
加上这个,那个错误就会消失
BlueJeans API是使用Swagger代码生成项目构建的,我设法让它在开发站点上运行(https://bluejeans.github.io/api-rest-meetings/site/index.html)通过填写有效负载中的字段(描述、名称、应用程序徽标URL和重定向URL)。
问题内容: 自数小时以来,我一直在尝试纠正http错误,但它仍显示不支持的页面。我在邮递员中添加标题。 这是我的Java代码 这是我的档案 问题答案: 通过和如何在响应流和请求流之间对对象进行序列化和反序列化。 将会发生的是,将从提供者的注册表中进行搜索,以查找可以处理的媒体类型。如果找不到,则Jersey无法处理该请求,并将发送415不支持的媒体类型。通常,你还应该在服务器端记录一个异常。不知道
我已经创建了一个示例web服务来进行post调用。 我使用的是Jersey JAX-RS和Maven。
问题内容: 我正在尝试使用jQuery 1.6(Jackson 2.1.1 和Spring 3.2.0 )通过JSON通过该方法向数据库中插入和/或更新数据。 JS代码如下。 通过URL映射的Spring控制器内部的方法如下。 服务器按照问题的含义进行响应, 415不支持的媒体类型 标头信息如下所示。 整个文件如下。 当我删除一个方法参数并仅用于接受请求参数时,它可以工作。 问题答案: 浏览器发送
问题内容: 我正在使用Spring 3.2,并尝试使用ajax发布请求来提交json对象数组。如果相关,我转义了所有特殊字符。 我的HTTP状态为415。 我的控制器是: jQuery是: 我发布的数组中的对象之一的示例是以下json: 错误是: 为什么会发生此错误-有人知道吗? 问题答案: 您可以尝试使用。它没有任何问题
我有一个问题,当我需要插入用户到Keycloak时,我出现了以下错误: 消息:“http failure response for http://localhost:8080/auth/admin/realms/demo/clients:415 Unsupported Media type”名称:“httperrorresponse”确定:false状态:415 statusText:“Unsup