Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Change Log
## [4.58.5](https://github.com/plivo/plivo-python/tree/v4.58.5) (2025-02-18)
**Feature - Throw GeoPermissionError on synchronous geopermissions error**

## [4.58.4](https://github.com/plivo/plivo-python/tree/v4.58.4) (2025-01-27)
- Role param validation enhancement in Multiparty Add Participant API and XML creation
Expand Down
3 changes: 3 additions & 0 deletions plivo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ class ValidationError(PlivoRestError):

class ForbiddenError(PlivoRestError):
pass

class GeoPermissionError(PlivoRestError):
pass
14 changes: 13 additions & 1 deletion plivo/rest/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from plivo.base import ResponseObject
from plivo.exceptions import (AuthenticationError, InvalidRequestError,
PlivoRestError, PlivoServerError,
PlivoRestError, PlivoServerError, GeoPermissionError,
ResourceNotFoundError, ValidationError)
from plivo.utils import is_valid_mainaccount, is_valid_subaccount
from plivo.version import __version__
Expand All @@ -21,6 +21,8 @@
PLIVO_API = 'https://api.plivo.com'
PLIVO_API_BASE_URI = '/'.join([PLIVO_API, 'v1/Account'])

GEO_PERMISSION_ENDPOINTS = ['/Message/', '/Call/', '/Session/']


def get_user_agent():
return 'plivo-python/%s (Python: %s)' % (__version__,
Expand Down Expand Up @@ -114,6 +116,16 @@ def process_response(self,
raise AuthenticationError(
'Failed to authenticate while accessing resource at: '
'{url}'.format(url=response.url))

if \
response.status_code == 403 and \
method == "POST" and \
any(response.url.endswith(endpoint) for endpoint in GEO_PERMISSION_ENDPOINTS):
if response_json and 'error' in response_json:
raise GeoPermissionError(response_json.error)
raise GeoPermissionError(
'Request Failed : '
'{url}'.format(url=response.url))

if response.status_code == 404:
if response_json and 'error' in response_json:
Expand Down
11 changes: 8 additions & 3 deletions plivo/rest/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from plivo.base import ResponseObject
from plivo.exceptions import (AuthenticationError, InvalidRequestError,
PlivoRestError, PlivoServerError,
PlivoRestError, PlivoServerError, GeoPermissionError,
ResourceNotFoundError, ValidationError, ForbiddenError)
from plivo.resources import (Accounts, Addresses, Applications, Calls, Token,
Conferences, Endpoints, Identities,
Expand Down Expand Up @@ -44,6 +44,8 @@

CALLINSIGHTS_BASE_URL = 'https://stats.plivo.com'

GEO_PERMISSION_ENDPOINTS = ['/Message/', '/Call/', '/Session/']


def get_user_agent():
return 'plivo-python/%s (Python: %s)' % (__version__,
Expand Down Expand Up @@ -172,9 +174,12 @@ def process_response(self,
'{url}'.format(url=response.url))

if response.status_code == 403:
error = ForbiddenError
if method == "POST" and any(response.url.endswith(endpoint) for endpoint in GEO_PERMISSION_ENDPOINTS):
error = GeoPermissionError
if response_json and 'error' in response_json:
raise ForbiddenError(response_json.error)
raise ForbiddenError(
raise error(response_json.error)
raise error(
'Request Failed : '
'{url}'.format(url=response.url))

Expand Down
2 changes: 1 addition & 1 deletion plivo/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '4.58.4'
__version__ = '4.58.5'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='plivo',
version='4.58.4',
version='4.58.5',
description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML',
long_description=long_description,
url='https://github.com/plivo/plivo-python',
Expand Down
Loading