mirror of
https://github.com/OpenMTC/OpenMTC.git
synced 2025-03-03 03:58:35 +00:00
* changes starting with python3 explicit * removes python modules which are not available for python3 * exchanges fyzz query parsing with rdflib functionality * fixes interop tests * replaces reduce with for loop in nodb driver * simple python2 -> python3 conversions * adds changes for handling different string handling in python3 * test stretch building with travis * installing python-setuptools in docker * installing python-setuptools in docker * changing python2 to python3 in docker makefiles * changing python2 to python3 and some other test changes * push docker only in master branche * running version of openmtc * fix some port problems * porting path library completly now * restoring travis.yml * testing new travis.yml * add sudo * updating travis OS from trusty to xenial * upgrade pip before * show running docker logs * show more logs * for debugging * showlogs of docker after failure * testing new travis.yml * finish travis.yml
29 lines
887 B
Python
29 lines
887 B
Python
# Example 12a: Making Requests with error handling
|
|
|
|
from openmtc_onem2m.client.http import OneM2MHTTPClient
|
|
from openmtc_onem2m.transport import OneM2MRequest, OneM2MErrorResponse
|
|
from openmtc.exc import OpenMTCError
|
|
|
|
client = OneM2MHTTPClient("http://localhost:8000", False)
|
|
|
|
try:
|
|
onem2m_request = OneM2MRequest("retrieve", to="onem2m")
|
|
promise = client.send_onem2m_request(onem2m_request)
|
|
onem2m_response = promise.get()
|
|
except OneM2MErrorResponse as e:
|
|
print("CSE reported an error:", e)
|
|
raise
|
|
except OpenMTCError as e:
|
|
print("Failed to reach the CSE:", e)
|
|
raise
|
|
else:
|
|
pass
|
|
|
|
# no exception was raised, the method returned normally.
|
|
print(onem2m_response.to)
|
|
#>>> onem2m
|
|
print(onem2m_response.response_status_code)
|
|
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
|
print(onem2m_response.content)
|
|
#>>> CSEBase(path='None', id='cb0')
|