Jun 26, 2020 07:17 AM
Hi everyone!
I have a table, a collection of URLs to different articles and videos. I wanted to have the text parsed from these URLs (the content of the article, description of a youtube video). I made it with python (beautifulsoup4) and made a serverless function for this. When I’m running it in scripting block, it gives an error message (‘TypeError: Failed to fetch at Failed to fetch’). It appears sometimes after passing perfectly 10 URLs and sometimes after 38, or after 3. So it looks completely random. When it runs to an error, I test it with the serverless function outside of Airtable’s scripting block, and it works fine there.
Do you know anything, what could cause the error in random lines?
Thank you in advance for the help!
Solved! Go to Solution.
Jun 30, 2020 04:34 PM
The intermittent Failed to fetch
error suggests that sometimes your serverless function is failing to return a valid response.
When this happens, you can debug it by looking at the Network panel of the browser’s developer tools.
Jun 26, 2020 08:19 AM
Can you paste the code for your script here? I wonder if some of the URLs cause the serverless function to throw an error, which would then make the fetch
fail as well.
Jun 30, 2020 12:22 AM
Sure, here is the script code:
const table = base.getTable(“Content”);
const query = await table.selectRecordsAsync()
for (let record of query.records) {
const articleUrl = record.getCellValueAsString(“URL”);
const response = await fetch( https://mtgzblpjf0.execute-api.us-east-1.amazonaws.com/dev/hello?url=${articleUrl}
);
const data = await response.json();
console.log(‘articleUrl’, articleUrl);
table.updateRecordAsync(record, {
“Article’s Title”: data.title,
“Article’s Content”: data.text,
});
}
I’m checking if it works with the console.log function.
Jun 30, 2020 02:16 PM
In the examples, fetch
uses the config option cors: true,
, so maybe try that. There’s also some config on Amazon to enable CORS.
Jun 30, 2020 04:34 PM
The intermittent Failed to fetch
error suggests that sometimes your serverless function is failing to return a valid response.
When this happens, you can debug it by looking at the Network panel of the browser’s developer tools.
Jul 01, 2020 02:34 AM
Thanks! I modified the serverless function a bit and it runs well now. It just have a problem with the youtube links, but that is a different topic :slightly_smiling_face: