ringcentral / ringcentral-python Goto Github PK
View Code? Open in Web Editor NEWRingCentral Connect Platform Python SDK
License: MIT License
RingCentral Connect Platform Python SDK
License: MIT License
how to get mms attachment need a demo
Update custom User Agent header, currently RC-User-Agent
to X-User-Agent
to match JS SDK.
Current Python SDK:
ringcentral-python/ringcentral/platform/platform.py
Lines 142 to 143 in 419378d
JS SDK:
Hi I am reading through the code and can not figure how to set a parameter in builder to not include the coverpage. Would really appreciate guidance on this.
There is no need to specify it. Because the server knows what content type to return. There is no ambiguity.
And since we specify json as the accept type, binary downloading stops working recently (due to a recent change on server side)
There is idleTimeout, by default it's 30 minutes. If in 30 minutes there is no traffic, the connection will time out:
{
"errorCode": "WSG-902",
"message": "Idle timeout expired"
}
WebSocket ping frame doesn't count as traffic, so you cannot rely on WebSocket library's auto-ping feature.
It's not a problem for apps with lots of traffic. But for app with not so much traffic, the notification will stop working after 30 minutes.
Refer to the implementation in C# https://github.com/ringcentral/RingCentral.Net/blob/master/RingCentral.Net.WebSocket/WebSocketExtension.cs#L90-L101
The PyPI ringcentral 0.7.5
package does not include the core
folder.
This results in the following error:
File "/path/to/python3.6/site-packages/ringcentral/platform/platform.py", line 8, in <module>
from ..core import base64encode
ModuleNotFoundError: No module named 'ringcentral.core'
A workaround is to download the files from the Github repo and save them into the site-packages/ringcentral
directory manually.
MMS is now supported in the API. This is similar to Fax support.
Below error stopping the build while migrating to GitHub actions.
ModuleNotFoundError: No module named 'requests_mock'
LM796TTVT:ringcentral-python a.lohith$ /usr/local/bin/python3 "/Users/a.lohith/Desktop/RC New pull/ringcentral-python/ringcentral/platform/platform_test.py"
Traceback (most recent call last):
File "/Users/a.lohith/Desktop/RC New pull/ringcentral-python/ringcentral/platform/platform_test.py", line 6, in
import requests_mock
ModuleNotFoundError: No module named 'requests_mock'
Problems>
[{
"resource": "/Users/a.lohith/Desktop/RC New pull/ringcentral-python/ringcentral/platform/platform_test.py",
"owner": "generated_diagnostic_collection_name#0",
"code": {
"value": "reportMissingImports",
"target": {
"$mid": 1,
"path": "/microsoft/pyright/blob/main/docs/configuration.md",
"scheme": "https",
"authority": "github.com",
"fragment": "reportMissingImports"
}
},
"severity": 4,
"message": "Import "requests_mock" could not be resolved",
"source": "Pylance",
"startLineNumber": 7,
"startColumn": 8,
"endLineNumber": 7,
"endColumn": 21
}]
$ pip install --no-cache-dir ringcentral==0.7.8
Collecting ringcentral==0.7.8
Downloading ringcentral-0.7.8.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/0j/s3120gnd50zd0nqy1bknhclw0000gp/T/pip-build-YpAq3C/ringcentral/setup.py", line 15, in <module>
install_requires=[i.strip() for i in open('requirements.txt').readlines()],
IOError: [Errno 2] No such file or directory: 'requirements.txt'
versus 0.7.7:
$ pip install --no-cache-dir ringcentral==0.7.7
Collecting ringcentral==0.7.7
Downloading ringcentral-0.7.7.tar.gz
Requirement already satisfied: observable>=0.3.1 in ./Library/Python/2.7/lib/python/site-packages (from ringcentral==0.7.7)
Requirement already satisfied: pubnub==4.* in ./Library/Python/2.7/lib/python/site-packages (from ringcentral==0.7.7)
Requirement already satisfied: pycryptodome>=3.4.4 in ./Library/Python/2.7/lib/python/site-packages (from ringcentral==0.7.7)
Requirement already satisfied: requests>=2.7.0 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from ringcentral==0.7.7)
Requirement already satisfied: pycryptodomex>=3.3 in ./Library/Python/2.7/lib/python/site-packages (from pubnub==4.*->ringcentral==0.7.7)
Requirement already satisfied: six>=1.10 in ./Library/Python/2.7/lib/python/site-packages (from pubnub==4.*->ringcentral==0.7.7)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests>=2.7.0->ringcentral==0.7.7)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests>=2.7.0->ringcentral==0.7.7)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.7.0->ringcentral==0.7.7)
Requirement already satisfied: idna<2.7,>=2.5 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.7.0->ringcentral==0.7.7)
Installing collected packages: ringcentral
Running setup.py install for ringcentral ... done
Successfully installed ringcentral-0.7.7
Happens on a MacBook Pro on High Sierra, and on an AmazonLinux OS.
Move pdoc from requirements.txt to requirements-dev.txt
Because it is only required in development time. Developers who install this SDK don't need pdoc.
such as demo_mms.py an demo_fax.py
Unable to install RingCentral Python Module with PIP on my computer.
The Error
C:\WINDOWS\system32>pip install ringcentral
Collecting ringcentral
Using cached ringcentral-0.7.11.tar.gz (13 kB)
Requirement already satisfied: observable==0.3.* in c:\users\erik\appdata\local\programs\python\python38-32\lib\site-packages (from ringcentral) (0.3.2)
Collecting pubnub==4.*
Using cached pubnub-4.3.0.tar.gz (49 kB)
Collecting pycryptodome==3.*
Using cached pycryptodome-3.9.6-cp38-cp38-win32.whl (14.1 MB)
Requirement already satisfied: requests==2.* in c:\users\erik\appdata\local\programs\python\python38-32\lib\site-packages (from ringcentral) (2.22.0)
Requirement already satisfied: pycryptodomex>=3.3 in c:\users\erik\appdata\local\programs\python\python38-32\lib\site-packages (from pubnub==4.->ringcentral) (3.9.6)
Requirement already satisfied: six>=1.10 in c:\users\erik\appdata\local\programs\python\python38-32\lib\site-packages (from pubnub==4.->ringcentral) (1.14.0)
Collecting cbor2
Using cached cbor2-5.0.1.tar.gz (72 kB)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\erik\appdata\local\programs\python\python38-32\lib\site-packages (from requests==2.->ringcentral) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\erik\appdata\local\programs\python\python38-32\lib\site-packages (from requests==2.->ringcentral) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\erik\appdata\local\programs\python\python38-32\lib\site-packages (from requests==2.->ringcentral) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\erik\appdata\local\programs\python\python38-32\lib\site-packages (from requests==2.->ringcentral) (1.25.8)
Installing collected packages: cbor2, pubnub, pycryptodome, ringcentral
Running setup.py install for cbor2 ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\erik\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\erik\AppData\Local\Temp\pip-install-pmw2qdup\cbor2\setup.py'"'"'; file='"'"'C:\Users\erik\AppData\Local\Temp\pip-install-pmw2qdup\cbor2\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\erik\AppData\Local\Temp\pip-record-946solcx\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\erik\appdata\local\programs\python\python38-32\Include\cbor2'
cwd: C:\Users\erik\AppData\Local\Temp\pip-install-pmw2qdup\cbor2
Complete output (14 lines):
running install
running build
running build_py
creating build
creating build\lib.win32-3.8
creating build\lib.win32-3.8\cbor2
copying cbor2\compat.py -> build\lib.win32-3.8\cbor2
copying cbor2\decoder.py -> build\lib.win32-3.8\cbor2
copying cbor2\encoder.py -> build\lib.win32-3.8\cbor2
copying cbor2\types.py -> build\lib.win32-3.8\cbor2
copying cbor2_init.py -> build\lib.win32-3.8\cbor2
running build_ext
building 'cbor2' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\erik\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\erik\AppData\Local\Temp\pip-install-pmw2qdup\cbor2\setup.py'"'"'; file='"'"'C:\Users\erik\AppData\Local\Temp\pip-install-pmw2qdup\cbor2\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\erik\AppData\Local\Temp\pip-record-946solcx\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\erik\appdata\local\programs\python\python38-32\Include\cbor2' Check the logs for full command output.
It appears that the PubNub Python SDK has been updated and is no longer building on Travis CI as shown in build 172716958 due to a change in the AES constructor signature. Specifically, the AES.new
constructor now takes 2+ arguments instead of the previous 1 argument. Please resolve by upgrading to latest Python SDK.
The following is excerpted from Travis build 172716958:
File "/home/travis/build/ringcentral/ringcentral-python/ringcentral/subscription/subscription.py", line 188, in _decrypt
obj2 = AES.new(key)
TypeError: new() takes at least 2 arguments (1 given)
In rcsdk/platform/init.py, on line 49 in the authorize method there is a typo. 'access_toket_ttl' should be 'access_token_ttl'.
Windows 10 64-bit, PowerShell.
pip install ringcentral
Collecting ringcentral
Using cached ringcentral-0.6.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\tyler\appdata\local\temp\pip-build-geexp8\ringcentral\setup.py", line 3, in <module>
VERSION = __import__("ringcentral").VERSION
File "ringcentral\__init__.py", line 4, in <module>
from .sdk import SDK
File "ringcentral\sdk.py", line 6, in <module>
from .mocks import Registry
File "ringcentral\mocks\__init__.py", line 4, in <module>
from .client import Client
File "ringcentral\mocks\client.py", line 5, in <module>
import requests
ImportError: No module named requests
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\tyler\appdata\local\temp\pip-build-geexp8\ringcentral\
I checked setup.py
and I did see
install_requires=[
'pubnub>=3.7.0',
'requests>=2.7.0'
],
I have no idea what's the root cause.
Please, provide direct support for multi-part requests, so that users can send Faxes easily. So far, the request has to be prepared manually, and submitted to the SDK like this:
message = {
"from": {"phoneNumber": send_from_number},
"to": [{"phoneNumber": send_to_number}],
"text": message_text
}
attachments = \
[ ("json", ("", json.dumps(message), "application/json"))]\
+\
[ ("attachment", (file_name, open(file_name, "rb"), "image/png")) for file_name in attachments_files]
req = requests.Request("POST", "/account/~/extension/~/fax", files=attachments)
rsp=pla.send_request(req)
https://pypi.org/project/observable/
Note: We are Python 3 only! Only Python Versions >= 3.5 are supported. Use v0.3.2 for older Python Versions.
This SDK specifies observable>=0.3.1
in requirements. I think we need to change it to observable==0.3.2
When I try to fetch Users list via SCIM URI using:
platform.get("/scim/v2/Users")
It is automatically converted to https://platform.devtest.ringcentral.com/restapi/v1.0/scim/v2/Users
i.e. /restapi/v1.0
prepended to the URL.
and results in "Invalid URI" exception.
This is code snippet communicating with RC API that attempts to send a pdf doc for faxing.
` rcsdk = SDK(RINGCENTRAL_CLIENTID,
RINGCENTRAL_CLIENTSECRET, RINGCENTRAL_SERVER)
platform = rcsdk.platform()
platform.login(RINGCENTRAL_USERNAME,
RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD)
# platform.login(jwt=RC_JWT)
builder = rcsdk.create_multipart_builder()
builder.set_body({
'to': [{'phoneNumber': recipient}],
'faxResolution': "High",
'coverPageText': "Clinic Name \n" + str(sender)
})
with open(faxdoc, encoding="utf8", errors='ignore') as f:
content = f.read()
attachment = (faxdoc, content)
builder.add(attachment)
request = builder.request('/account/~/extension/~/fax')
resp = platform.send_request(request)`
Everything looks good and this is output in terminal
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): platform.devtest.ringcentral.com:443 DEBUG:urllib3.connectionpool:https://platform.devtest.ringcentral.com:443 "POST /restapi/oauth/token HTTP/1.1" 200 574 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): platform.devtest.ringcentral.com:443 DEBUG:urllib3.connectionpool:https://platform.devtest.ringcentral.com:443 "POST /restapi/v1.0/account/~/extension/~/fax HTTP/1.1" 200 None INFO:root:E:\pyfaxrc\apps\response\12047861522__E:\pyfaxrc\apps\outbound\test.pdf
The fax that is received is 2 pages, a cover page and a 2nd page that has a watermark saying "test fax using ring central developer account"
The Sandbox Console shows the service as having a successful transmission, even though the attachment was not sent.
if I test with a jpeg attachment, I do not receive any fax and the event logs are identical as the pdf, with exception of the filename and extension.
Any advisement appreciated.
PS: (the code snippet that opens the file was changed per RC community advisement as I was receiving errors when using the original code sample.
I have 4 calls without recording and 1 call with recording visible in my call list in my service.devtest.ringcentral.com admin portal. When I try to collect call log using
platform.get('/account/~/extension/~/call-log', request_params)
I keep getting inconsistent results.
When I try requesting results with perPage=10
and page=1
response contains all 4 calls, but paging
has {pageStart: 0, perPage: 10, page: 1, pageEnd: 3}
. pageEnd
parameter is obviously wrong (disregarding the fact that pageStart
starts with 0, and page
starts with 1).
When requesting with perPage=2
things are equally perplexing. Starting withpage=1
I get what I would expect: 2 results and {pageStart: 0, perPage: 2, page: 1, pageEnd: 1}
. But for some reason repeating request with page=2
returns 0 results with paging
containing just {perPage: 10, page: 1}
(no pageEnd
and pageStart
fields).
Any ideas how to overcome this?
I tried to run this command as stated in our README.md pip install ringcentral
to install the SDK but ran into this error:
File "/tmp/easy_install-zTh0kz/setuptools_scm-6.0.1/src/setuptools_scm/utils.py", line 41
print(*k)
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-OZLxz1/cbor2/
It is because the default pip pointed to version 2.7 which is now in 'end of life' status Python https://www.python.org/downloads/ so it didn't work and then when I tried to install using pip3 install ringcentral
that worked successfully. I'll submit a PR with the fix.
Can't pull script content from API. This endpoint pulls script metadata but won't return content:
/api/v1/admin/accounts/{RINGCENTRAL_ACCOUNT_ID}/scriptGroups/{script_group_id}/scripts/{script_id}/
Only password flow is supported.
https://devcommunity.ringcentral.com/ringcentraldev/topics/glip-bot-with-python
multipart/mixed
support needed.
POST /restapi/v1.0/account/~/extension/~/greeting
only supports multipart/mixed
. So there is no way to do the same thing mentioned in the blog article with this SDK.
Fax sending and MMS sending do support multipart/form-data
. But there are still endpoints which requires multipart/mixed
.
I am going to submit a PR soon.
The API Reference supports a "Try it out" feature which allows someone to copy-and-paste a code sample that just works. This system works well for cURL requests because the framework is able to insert the HTTP Bearer token directly into the "code sample." However, we cannot do that with any specific language because there is not a clear/obvious way to initialize the client/SDK with an already-existant token.
We need a simple and single API call for getting the Bearer token in this SDK. Something to the effect of:
sdk.platform().auth().setData(...)
If a capability like this already exists, then can we add that to the documentation?
Acceptance criteria includes the very subjective criteria of the solution not feeling like a "hack." It should not feel like the developer is going into set the value via a backdoor, but by setting it via a public and sanctioned manner.
Hello, I am using this code to attempt to send an SMS message throug RingCentral Sandbox Server, It is throwing "Refresh Token has expired at patform.login() I am using Python 3.6 64bit and VS2017 on Win8.1 have also tried using 3.7 on same platform.
Thanks for your help
from ringcentral import SDK
sdk = SDK(CLIENT_ID, CLIENT_SECRET, SERVER)
platform = sdk.platform()
try :
platform.login("+nnnnnnnn", "xxx", "xxxxxx") #Throws Refresh token has expired
except Exception as e: print(str(e))
builder = sdk.create_multipart_builder()
builder.set_body({
'from': {'phoneNumber': '+nnnn'},
'to': [{'phoneNumber': '+nnnn'}],
'text': 'Try this from RC!'
})
request = builder.request('/account/~/extension/~/sms')
response = platform.send_request(request)
print("Response " + response)
SSIA - Let's add a more common code sample use case to the README - a simple SMS script
Issue below is reported by a developer:
This is the code where the issue begins:
...
attachment = ('fax.jpg', open('fax.jpg','r').read(), 'image/jpeg')
builder.add(attachment)
...
This is the error that I get when I attach a document:
File "/home/username/Projects/project-paths/fax.py", line 71, in send_fax
resp = platform.send_request(request)
File "/home/username/.local/lib/python3.9/site-packages/ringcentral/platform/platform.py", line 173, in send_request
return self._client.send(self.inflate_request(request, skip_auth_check=skip_auth_check))
File "/home/username/.local/lib/python3.9/site-packages/ringcentral/http/client.py", line 34, in send
raise ApiException(response, e)
File "/home/username/.local/lib/python3.9/site-packages/ringcentral/http/api_exception.py", line 14, in init
if api_response.error():
File "/home/username/.local/lib/python3.9/site-packages/ringcentral/http/api_response.py", line 77, in error
message = message + ' (and additional error happened during JSON parse: ' + e.message + ')'
AttributeError: 'Exception' object has no attribute 'message'
Just a friendly reminder that the GitHub release tags are at 0.8.1 while the PyPI package is at 0.8.3.
Issue:
TypeError: not a valid non-string sequence or mapping object
Replicate:
platform.delete('/subscription', 'subscriptionid')
You can send a dict, but it is not clear what key should be used.
When running the README.md
example subscription code, the following error is encountered:
No Pubnub SDK, skipping Pubnub test
PubNub is verified to be installed:
$ pip3 show pubnub
Name: pubnub
Version: 4.0.9
Perhaps there's an issue with the import line, import Pubnub
, using PubNub 4.x?
PubNub SDK documentation uses from pubnub.pubnub import PubNub
.
Hi Team, hopefully this is right place to ask, if not, I'd appreciate if you can direct me.
I'm the founder of cloudquery.io, a high performance open source ELT framework.
Our users are interested in a RingCentral plugin, but as we cannot maintain all the plugins ourselves, I was curious if this would be an interesting collaboration, where we would help implement an initial source plugin, and you will help maintain it.
This will give your users the ability to sync RingCentral data to any of their datalakes/data-warehouses/databases easily using any of the growing list of CQ destination plugins.
Best,
Yevgeny
Can we get a sample Credentials.ini file that could be used? Currently , I don't see any sample file that could be used as a format.
We are using OAuth 2.0 Authorization Code Flow and save tokens to our DB.
We process webhooks that we receive from ringcentral in background tasks.
Each time a background task is run, we have to initialise the SDK with authentication data. Since expire_time
and refresh_token_expire_time
are calculated whenever auth data is being set, this will not work for us.
Is there a way we can use the sdk for this use case?
Please allow Python SDK to have body the delete extension API endpoint
Current behavior : this is not working, throws a 400 error, because usually delete does not have a body, but in this case it;s required cos that's how it is in the documentation
try:
endpoint = "/restapi/v2/accounts/~/extensions"
body = {
"keepAssetsInInventory": True,
"records": [{"id": "63581676004"}]
}
res = platform.delete(endpoint, body)
like SUB-406
etc, not just error message.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.