watson_developer_cloud.watson_service module

load_from_vcap_services(service_name)[source]
exception WatsonException[source]

Bases: Exception

Custom exception class for Watson Services.

exception WatsonApiException(code, message, info=None, httpResponse=None)[source]

Bases: watson_developer_cloud.watson_service.WatsonException

Custom exception class for errors returned from Watson APIs.

Parameters:
  • code (int) – The HTTP status code returned.
  • message (str) – A message describing the error.
  • info (dict) – A dictionary of additional information about the error.
  • httpResponse (response) – response
exception WatsonInvalidArgument[source]

Bases: watson_developer_cloud.watson_service.WatsonException

datetime_to_string(datetime)[source]

Serializes a datetime to a string. :param datetime: datetime value :return: string. containing iso8601 format date string

string_to_datetime(string)[source]

Deserializes string to datetime. :param string: string containing datetime in iso8601 format :return: datetime.

get_error_message(response)[source]

Gets the error message from a JSON response. :return: the error message :rtype: string

class DetailedResponse(response=None, headers=None, status_code=None)[source]

Bases: object

Custom class for detailed response returned from Watson APIs.

Parameters:
  • response (Response) – Either json response or http Response as requested.
  • headers (dict) – A dict of response headers
  • status_code (str) – HTTP response code
get_result()[source]
get_headers()[source]
get_status_code()[source]
class WatsonService(vcap_services_name, url, username=None, password=None, use_vcap_services=True, api_key=None, iam_apikey=None, iam_access_token=None, iam_url=None)[source]

Bases: object

set_username_and_password(username=None, password=None)[source]
set_api_key(api_key)[source]
set_token_manager(iam_apikey=None, iam_access_token=None, iam_url=None)[source]
set_iam_access_token(iam_access_token)[source]
set_iam_apikey(iam_apikey)[source]
set_url(url)[source]
set_default_headers(headers)[source]

Set http headers to be sent in every request. :param headers: A dictionary of header names and values

set_http_config(http_config)[source]

Sets the http client config like timeout, proxies, etc.

disable_SSL_verification()[source]
set_detailed_response(detailed_response)[source]
static unpack_id(dictionary, label_id)[source]
request(method, url, accept_json=False, headers=None, params=None, json=None, data=None, files=None, **kwargs)[source]