Does this quick start code work for you? Since you are running Python 3.x, just add the brackets to the print content and run the code.
Hi Phong, I get the same error. Here is code snippet I am testing excluding my RC Credentials:
# Ring Central Fax Bridge for MaxFax -push to Github
import sys
from ringcentral import SDK
# ---------------------Test Received Parameters--Validate type and length----------
recipient = str(sys.argv[1])
faxdoc = str(sys.argv[2])
sender = str(sys.argv[3])
if len(recipient) < 9:
print('Fax# is incomplete, expecting 9 digits')
elif len(faxdoc) < 1:
print('File name to be faxed is missing')
else:
# insert code for directory and variable initialization
# try:
# --------------------RingCentral Fax Send Logic----------------------------------
RINGCENTRAL_CLIENTID = ''
RINGCENTRAL_CLIENTSECRET = ''
RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com'
RINGCENTRAL_USERNAME = ''
# RINGCENTRAL_USERNAME = ''
RINGCENTRAL_PASSWORD = ''
RINGCENTRAL_EXTENSION = '101'
rcsdk = SDK(RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, RINGCENTRAL_SERVER)
platform = rcsdk.platform()
platform.login(RINGCENTRAL_USERNAME, RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD)
builder = rcsdk.create_multipart_builder()
builder.set_body({
'to': [{'phoneNumber': recipient}],
'faxResolution': "High",
'coverPageText': "Clinic Name
" + sender
})
attachment = (faxdoc, open(faxdoc, 'r').read(), 'image/jpg')
builder.add(attachment)
request = builder.request('/account/~/extension/~/fax')
resp = platform.send_request(request)
print('Fax sent. Message status: ' + resp.json().messageStatus)
# except (exc_type, exc_value, exc_traceback):
# Notify that an error occurred executing send.
print(['An error occurred while attempting to contact RingCentral'])
Thanks for looking.
I found some change in Python 3. I got the same error using the old code too.
Change this and it should work
...
with open('test.jpg', encoding="utf8", errors='ignore') as f:
content = f.read()
attachment = ('test.jpg', content)
builder.add(attachment)
request = builder.request('/account/~/extension/~/fax')
response = platform.send_request(request)
print ('Fax sent. Current status: ' + response.json().messageStatus)
Let me know if it still not working for you.