question

Fausto Chepil avatar image
Fausto Chepil asked Phong Vu commented

Fax API unable to load attachment

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.

fax
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered Phong Vu commented

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.

2 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Fausto Chepil avatar image Fausto Chepil commented ·

Thank you Phong!

I am a newbie to Python and RC. Your code addressed what I suspected was the issue, but did not know the approach to take to fix it.

Fausto

0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Fausto Chepil commented ·

Great to hear that it helps. BTW, do you mind to accept the answer so other can see it better if they face the same issue. Thanks

0 Likes 0 ·
Fausto Chepil avatar image
Fausto Chepil answered Phong Vu converted comment to answer

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.


1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered Phong Vu commented

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.

2 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Fausto Chepil avatar image Fausto Chepil commented ·

Hi Phong,

I no longer get any errors and now that app is in production I am seeing that the content of the attachment faxed is blank. A page is being sent for the faxed pdf that was passed, but the content is a blank page with header information on top edge of the page faxed.

I have tried a few different pdf files and I get the same result.

Please advise,

Fausto

0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Fausto Chepil commented ·

Can you open a support ticket for this. The dev support team will have a look at your production account and help you.

1 Like 1 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys