Network is unreachable error

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

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.

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.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.