Sadanand_Shenoy | 2019-02-13 00:18:02 UTC | #1
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['httpproxy'] = proxy _ os.environ['HTTPPROXY'] = proxy_ os.environ['httpsproxy'] = proxy_ os.environ['HTTPSPROXY'] = 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 = { _ 'granttype': 'clientcredentials'_ }
# Get token response = requests.post('https://login.mypurecloud.com.au/oauth/token', data=requestBody, headers=requestHeaders)
# Check response if response.statuscode == 200:_ _ print ('Got token')_ else: _ print ('Failure: ' + str(response.statuscode) + ' - ' + response.reason) _ sys.exit(response.statuscode)
# Get JSON response body responseJson = response.json()
PureCloudPlatformClientV2.configuration.host = 'https://api.mypurecloud.com.au' PureCloudPlatformClientV2.configuration.accesstoken = responseJson['accesstoken']
apiinstance = PureCloudPlatformClientV2.UsersApi()_
try: _ # Get call history_ _ apiresponse = apiinstance.getusersme()_ _ pprint(apiresponse) 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
tim.smith | 2019-02-13 20:14:22 UTC | #2
My guess is that your network isn't allowing the traffic due to a firewall rule somewhere; that's generally the cause of "network is unreachable" errors. The Python SDK doesn't support using a proxy currently. I've created to API-4143 to track adding support for it.
Sadanand_Shenoy | 2019-02-13 21:53:24 UTC | #3
Thanks Tim. I have been informed we can only connect to the internet using the proxy server, so we will use the requests package for now to execute the APIs.
system | 2019-03-16 21:53:27 UTC | #4
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 4571