Response now has a .json method to pull the body out as a dictionary
This commit is contained in:
parent
d589b31180
commit
e39179da78
@ -1,6 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
|
|
||||||
class RequestError(Exception):
|
class RequestError(Exception):
|
||||||
pass
|
pass
|
||||||
@ -46,6 +47,17 @@ class Response:
|
|||||||
|
|
||||||
print(msg, file=self.out)
|
print(msg, file=self.out)
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
'''
|
||||||
|
Force an interpretation of json from the body
|
||||||
|
NOTE: this method is rather obtuse and a massive afterthough so its usage
|
||||||
|
should be limited as much as possible
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
return json.loads(self.body)
|
||||||
|
except:
|
||||||
|
return {}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
'''
|
'''
|
||||||
Returns: str(Response) -> `code => response.bdoy`
|
Returns: str(Response) -> `code => response.bdoy`
|
||||||
@ -79,7 +91,7 @@ class Request:
|
|||||||
raise RequestError('Invalid method passed')
|
raise RequestError('Invalid method passed')
|
||||||
|
|
||||||
|
|
||||||
def make(self, hope: int) -> Response:
|
def make(self, hope: int, auth: str) -> Response:
|
||||||
'''
|
'''
|
||||||
@param hope: int -> status code we hope to get back
|
@param hope: int -> status code we hope to get back
|
||||||
@return Response -> Wrapper around server http response
|
@return Response -> Wrapper around server http response
|
||||||
|
Loading…
Reference in New Issue
Block a user