loadImage() 403 Error

I am trying to load an image from a URL. Some images work, but sometimes the response is a 403 error message. When I try to open the URL’s in my browser they work fine, but not through the processing code.
One of the images that does not load is this one: https://spoonacular.com/recipeImages/660290-556x370.jpg
I looked into the http.request library, but I cannot find a way to open images with that.
how can I solve this problem?

Thank you in advance!

This happens a lot when js or different styles are used on that specific website.
A workaround is to publish it on Pinterest, and then right-click the image and copy the image link.
Just as a test I have done that with your image.

PImage img; 

void setup() { 
  size(557, 370); 
  img = loadImage("https://i.pinimg.com/564x/bd/ed/ba/bdedba17d9ca1d047a8036b7587cea79.jpg"); 
  image(img, 0, 0);

Thank you for you anwser @noel!
The link is provided by the Spoonacular Food API, and I need to open many of them through the code. So publishing every image on Pinterest is not really an option.
Do you know how I could solve this issue through code? Is there a way to send the appropriate header for example with the request?

I’ve searched quite a bit some time ago, but have found no solution.


I had the same problem as you with 403 error when trying to load image from an API.

Floflo gave me a solution today that solve my problem, maybe this can help you too:

1 Like