Make_xlsx utils.py method not allowed

Is there any way to solve this error when trying to call a function in xlsxutils.py using a client side scripting on the website?

image

This is the upper code, obviously there’s more but heres the exact call. I am trying to create a button that can export excel items of a doctype. I can use frappe.tools.downloadify but it only gives csv.
frappe.call({
method: “frappe.utils.xlsxutils.make_xlsx”,

Are you trying this with an administrator account?

Yes I am. The function is found in the frappe/utils/xlsxutils.py. Also to add,

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 95, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 47, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 82, in execute_cmd
    is_whitelisted(method)
  File "apps/frappe/frappe/__init__.py", line 781, in is_whitelisted
    throw(msg, PermissionError, title="Method Not Allowed")
  File "apps/frappe/frappe/__init__.py", line 534, in throw
    msgprint(
  File "apps/frappe/frappe/__init__.py", line 502, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 451, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.PermissionError: You are not permitted to access this resource.Function frappe.utils.xlsxutils.make_xlsx is not whitelisted.

It’s cause you’re trying to call a non-whitelisted function.

You could try to copy the entire code block (with all the imports) and try to imitate the function via calling to a custom .py file with the copied code block. It might work.

Can this be done without creating a custom app or modifying frappe files?

No, only whitelisted functions can be called via the form.call() method.

You could only try to import that function into a .py file, create a whitelisted function that uses that method and call it using the frm.call() method from a .js file (or client script).

You don’t really need a custom app for this, just create an api.py file (or some other name) in the frappe file directory and you can call into that path. (Custom apps are better cause you can export your modifications during version updates or to new servers.)

If you want a way to use it in the vanilla system with just client & server scripts, then I don’t have an idea on that.

1 Like