trying to write a Fax APP interface in python(3.9) using the ringcentral package and the sys module. Whenever app is called with document for transmission I get the following error:
decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 65: character maps to <undefined>
I believe issue with the the builder.set_body() function, specifically the builder.add(attachment) and how it handles the files being passed.
Any insights appreciated.
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.
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 \n" + 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.
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.
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder