mdeakyne / bbrest Goto Github PK
View Code? Open in Web Editor NEWBlackboard REST APIs... for humans?
License: MIT License
Blackboard REST APIs... for humans?
License: MIT License
From version 3900.26 it seems that swagger files are served from a domain like https://devportal-docstore.s3.amazonaws.com/learn-swagger-3900.26.0.json - Probably this will break this library.
When calling a bbrest method for a POST endpoint, the program outputs an unexpected argument message if I include query parameters.
In this particular case, I need to set both the POST and GET parameters in order to add an item to a child course.
from bbrest import BbRest
KEY = '~~~'
SECRET = '~~~'
URL = '~~~'
bb = BbRest(KEY, SECRET, URL)
payload = {
'title': 'Item',
'body': '<p>Item Content</p>',
'parentId': '~~~',
'contentHandler': {'id': 'resource/x-bb-document'}
}
bb.CreateChild(courseId=course_id,
contentId=content_id,
params={'allowChildCourseContent': True},
payload=payload)
outputs
TypeError: CreateChild() got an unexpected keyword argument 'params'
When trying the Upload function with a file as the payload it gives an error because of not JSON serializable.
Executed code:
with open('TiestoF.pdf', 'rb') as f:
payload = {'file': f}
bbObject.Upload(payload = payload)
Error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[46], line 10
8 with open('TiestoF.pdf', 'rb') as f:
9 payload = {'file': f}
---> 10 bbObject.Upload(payload = payload)
File <string>:1, in Upload(self, payload, params, sync)
File [~\AppData\Local\pypoetry\Cache\virtualenvs\bbultra-exploration-LkUm2ENX-py3.12\Lib\site-packages\bbrest.py:342](http://localhost:8888/lab/tree/python%20exploration/~/AppData/Local/pypoetry/Cache/virtualenvs/bbultra-exploration-LkUm2ENX-py3.12/Lib/site-packages/bbrest.py#line=341), in BbRest.call(self, summary, **kwargs)
338 self.refresh_token()
340 req = requests.Request(method=method, url=url, params=params, json=payload)
--> 342 prepped = self.session.prepare_request(req)
344 resp = self.session.send(prepped)
345 ret_resp = resp
File [~\AppData\Local\pypoetry\Cache\virtualenvs\bbultra-exploration-LkUm2ENX-py3.12\Lib\site-packages\requests\sessions.py:486](http://localhost:8888/lab/tree/python%20exploration/~/AppData/Local/pypoetry/Cache/virtualenvs/bbultra-exploration-LkUm2ENX-py3.12/Lib/site-packages/requests/sessions.py#line=485), in Session.prepare_request(self, request)
483 auth = get_netrc_auth(request.url)
485 p = PreparedRequest()
--> 486 p.prepare(
487 method=request.method.upper(),
488 url=request.url,
489 files=request.files,
490 data=request.data,
491 json=request.json,
492 headers=merge_setting(
493 request.headers, self.headers, dict_class=CaseInsensitiveDict
494 ),
495 params=merge_setting(request.params, self.params),
496 auth=merge_setting(auth, self.auth),
497 cookies=merged_cookies,
498 hooks=merge_hooks(request.hooks, self.hooks),
499 )
500 return p
File [~\AppData\Local\pypoetry\Cache\virtualenvs\bbultra-exploration-LkUm2ENX-py3.12\Lib\site-packages\requests\models.py:371](http://localhost:8888/lab/tree/python%20exploration/~/AppData/Local/pypoetry/Cache/virtualenvs/bbultra-exploration-LkUm2ENX-py3.12/Lib/site-packages/requests/models.py#line=370), in PreparedRequest.prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
369 self.prepare_headers(headers)
370 self.prepare_cookies(cookies)
--> 371 self.prepare_body(data, files, json)
372 self.prepare_auth(auth, url)
374 # Note that prepare_auth must be last to enable authentication schemes
375 # such as OAuth to work on a fully prepared request.
376
377 # This MUST go after prepare_auth. Authenticators could add a hook
File [~\AppData\Local\pypoetry\Cache\virtualenvs\bbultra-exploration-LkUm2ENX-py3.12\Lib\site-packages\requests\models.py:511](http://localhost:8888/lab/tree/python%20exploration/~/AppData/Local/pypoetry/Cache/virtualenvs/bbultra-exploration-LkUm2ENX-py3.12/Lib/site-packages/requests/models.py#line=510), in PreparedRequest.prepare_body(self, data, files, json)
508 content_type = "application/json"
510 try:
--> 511 body = complexjson.dumps(json, allow_nan=False)
512 except ValueError as ve:
513 raise InvalidJSONError(ve, request=self)
File [~\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py:238](http://localhost:8888/lab/tree/python%20exploration/~/AppData/Local/Programs/Python/Python312/Lib/json/__init__.py#line=237), in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
232 if cls is None:
233 cls = JSONEncoder
234 return cls(
235 skipkeys=skipkeys, ensure_ascii=ensure_ascii,
236 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
237 separators=separators, default=default, sort_keys=sort_keys,
--> 238 **kw).encode(obj)
File [~\AppData\Local\Programs\Python\Python312\Lib\json\encoder.py:200](http://localhost:8888/lab/tree/python%20exploration/~/AppData/Local/Programs/Python/Python312/Lib/json/encoder.py#line=199), in JSONEncoder.encode(self, o)
196 return encode_basestring(o)
197 # This doesn't pass the iterator directly to ''.join() because the
198 # exceptions aren't as detailed. The list call should be roughly
199 # equivalent to the PySequence_Fast that ''.join() would do.
--> 200 chunks = self.iterencode(o, _one_shot=True)
201 if not isinstance(chunks, (list, tuple)):
202 chunks = list(chunks)
File [~\AppData\Local\Programs\Python\Python312\Lib\json\encoder.py:258](http://localhost:8888/lab/tree/python%20exploration/~/AppData/Local/Programs/Python/Python312/Lib/json/encoder.py#line=257), in JSONEncoder.iterencode(self, o, _one_shot)
253 else:
254 _iterencode = _make_iterencode(
255 markers, self.default, _encoder, self.indent, floatstr,
256 self.key_separator, self.item_separator, self.sort_keys,
257 self.skipkeys, _one_shot)
--> 258 return _iterencode(o, 0)
File [~\AppData\Local\Programs\Python\Python312\Lib\json\encoder.py:180](http://localhost:8888/lab/tree/python%20exploration/~/AppData/Local/Programs/Python/Python312/Lib/json/encoder.py#line=179), in JSONEncoder.default(self, o)
161 def default(self, o):
162 """Implement this method in a subclass such that it returns
163 a serializable object for ``o``, or calls the base implementation
164 (to raise a ``TypeError``).
(...)
178
179 """
--> 180 raise TypeError(f'Object of type {o.__class__.__name__} '
181 f'is not JSON serializable')
TypeError: Object of type BufferedReader is not JSON serializable
Hi,
since in the class inizialization you grab the BB version, wouldn't be better to build the right swagger url with the version coded inside (like /portal/docs/apis/learn-swagger-3700.0.0.json
)?
In this way the attribute __all_functions
stores only the API methods available.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.