News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Fax API unable to load attachment
Tags: fax
Mar 30, 2022 at 12:19pm   •   3 replies  •  0 likes
Fausto Chepil

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.

3 Answers
answered on Mar 31, 2022 at 11:11am  

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.


 0
answered on Mar 31, 2022 at 9:52am  

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.



 0
answered on Mar 30, 2022 at 4:08pm  

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.


 1



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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us