Hi,
I am trying to test the Python SDK with the following code:
import base64, requests, sys
import time
import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.rest import ApiException
from pprint import pprint
import os
proxy = ""
_os.environ['http_proxy'] = proxy _
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
clientId = ''
clientSecret = ''
_ _
# Base64 encode the client ID and client secret
authorization = base64.b64encode(bytes(clientId + ':' + clientSecret, encoding='utf8'))
# Prepare for POST /oauth/token request
requestHeaders = {
_ 'Authorization': 'Basic ' + authorization.decode('utf-8'),_
_ 'Content-Type': 'application/x-www-form-urlencoded'_
}
requestBody = {
_ 'grant_type': 'client_credentials'_
}
# Get token
response = requests.post('https://login.mypurecloud.com.au/oauth/token', data=requestBody, headers=requestHeaders)
# Check response
if response.status_code == 200:
_ print ('Got token')_
else:
_ print ('Failure: ' + str(response.status_code) + ' - ' + response.reason)_
_ sys.exit(response.status_code)_
# Get JSON response body
responseJson = response.json()
PureCloudPlatformClientV2.configuration.host = 'https://api.mypurecloud.com.au'
PureCloudPlatformClientV2.configuration.access_token = responseJson['access_token']
api_instance = PureCloudPlatformClientV2.UsersApi()
try:
_ # Get call history_
_ api_response = api_instance.get_users_me()_
_ pprint(api_response)_
except ApiException as e:
_ print ("Exception when calling UsersApi: {}".format(e))_
print ('Done')
I am able to get the token successfully but the UsersApi call is returning the following error:
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.mypurecloud.com.au', port=443): Max retries exceeded with url: /api/v2/users/me (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f0330ce42b0>: Failed to establish a new connection: [Errno 101] Network is unreachable',))
What am I missing?
Regards
Sadanand