script-lab icon indicating copy to clipboard operation
script-lab copied to clipboard

Not allowed to request resource

Open genert opened this issue 2 years ago • 1 comments

Bug Report

  • Host: Excel
  • OS: macOS Big Sur 11.3
  • Browser: Microsoft Excel for Mac (v 16.54)
  • Environment: Production

Expected behavior:

Expected fetch to request CSV file over the internet.

Are there limitations for fetch that are not documented?

Actual behavior:

Returns "Not allowed to request" resource.

Screenshot 2021-10-25 at 15 37 41

Steps to Reproduce:

Use the following code to replicate the behaviour:

async function createMSCI() {
  await Excel.run(async (context) => {
    const response = await fetch('http://www.sca.isr.umich.edu/files/tbmics.csv', {
      headers: {
        'Content-Type': 'text/csv'
      },
      responseType: 'blob'
    });


    if (!response.ok) {
      throw Error("Response is not in OK state");
    }

    const data = response.blob();

    console.log(data);
  });
}

genert avatar Oct 25 '21 12:10 genert

I think the problem is related to the server settings. I uploaded the csv to my azure storage, and the first time, it also failed. And I set the cors to allow any origin access, and it works fine. You can try below sample code.

$("#run").click(() => tryCatch(run));

async function run() {
  await Excel.run(async (context) => {

    await fetch('https://chenxizhang.blob.core.windows.net/public/tbmics.csv', {
    }).then(x=>x.blob()).then(x=>console.log(x.size));
  });
}

/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
  try {
    await callback();
  } catch (error) {
    // Note: In a production add-in, you'd want to notify the user through your add-in's UI.
    console.error(error);
  }
}


chenxizhang avatar Sep 04 '22 14:09 chenxizhang

This is a great question for Stack Overflow.

wandyezj avatar Apr 16 '24 17:04 wandyezj