Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

rest_forbidden for media #2596

Closed
rafal-truszkowski opened this issue Jul 13, 2016 · 29 comments
Closed

rest_forbidden for media #2596

rafal-truszkowski opened this issue Jul 13, 2016 · 29 comments
Labels

Comments

@rafal-truszkowski
Copy link

rafal-truszkowski commented Jul 13, 2016

I am getting the following JSON object in a response for http://localhost/wp-json/wp/v2/posts/somePostID?_embed

"wp:featuredmedia":[  
   {  
      "code":"rest_forbidden",
      "message":"You don't have permission to do this.",
      "data":{  
         "status":403
      }
   }
]

also, wp-json/wp/v2/media is an empty array.

Is this a bug, or am I doing something wrong?

@BE-Webdesign
Copy link
Member

What user are you authenticating as, and what capabilities do they have? At the very least it is a really bad error message.

@rachelbaker
Copy link
Member

Perhaps this is the same issue as #2571

@rafal-truszkowski
Copy link
Author

No authentication. I am just doing a GET, not a POST.. for SOME media posts, a simple /wp-json/wp/v2/media/6639/ returns the above. Most of media posts work fine. I can't tell what the difference between them are..

@joehoyle
Copy link
Member

@rafalSuntimes if the attachment is attached to an unpublished post, you won't be able to read it. Is that the case here perhaps?

@petersowah
Copy link

@joehoyle Thanks. That solved it in my case.

@rmccue
Copy link
Member

rmccue commented Sep 12, 2016

Closing out, no response from the reporter in a month.

@rmccue rmccue closed this as completed Sep 12, 2016
@drewhallett
Copy link

drewhallett commented Apr 11, 2017

This issue is still happening with public, published posts. On my site everything is published and public.

The 403 error when accessing certain media is seemingly random.

@kadamwhite
Copy link
Contributor

@drewhallett Can you open a ticket on the WordPress support forums (at https://wordpress.org/support/forum/how-to-and-troubleshooting/ with the topic tag "rest-api") or bug tracker (at https://core.trac.wordpress.org)? This repository's issues are unfortunately no longer being tracked

@woodcipher
Copy link

We are experiencing this bug as well; if a bug has been filed, can you post a link to it here so that we can follow it?

@Werewolve
Copy link

I discovered this randomly appearing bug too. 403 error when accessing media of some public published posts. Any news on this topic?

@venanciorodrigo
Copy link

venanciorodrigo commented Apr 26, 2017

Same issue here:
bug

URL on my local environment: wp-json/wp/v2/posts?_embed&categories=1

@venanciorodrigo
Copy link

There is something weird related to the issue. I've uploaded a featured media on the "Pages" page, after that, I create a new post and pick up the same image uploaded on the "Pages" page. It causes the error that I posted above. But if you create a new post and upload a new image it works fine.

@elyobo
Copy link

elyobo commented Jun 1, 2017

Yeah, seeing the same problem here. Public post, still not letting the media embed, but it seems to work fine most of the time.

@Paul424
Copy link

Paul424 commented Jun 16, 2017

Same issue here:

{

"code": "rest_forbidden",
"message": "Sorry, you are not allowed to do that.",
"data": {
"status": 403
}
}

What role is required at minimum to access media? Seems that when i get all media i also see a subset?

Update: Seems to be related to WP Offload S3 Lite plugin that has not yet uploaded these images....

@netdelight
Copy link

netdelight commented Jun 21, 2017

Okay, based on what I've seen in the DB, I have more input regarding this evil issue.
Actually, a media is indexed in the posts table and have only one post_parent, even if it's featured in other posts. I assume this post_parent is the first post the media was linked to. So this parent is the post that must be public, no matter the status of the other posts.
Here's the query to know if the parent post of your file is public :
SELECT child.ID AS child_ID, parent.ID AS parent_ID, child.guid AS featuredmedia, child.post_status AS child_status, parent.post_status AS parent_status FROM `wp_posts` child JOIN `wp_posts` parent ON (child.post_parent = parent.ID) WHERE child.post_type = 'attachment'

A workaround if your media is related to a private parent is to switch its post_status from inherit to publish.

Hope this helps.

@stefanledin
Copy link

I just experienced the same issue. The image was originally uploaded as a featured image to a post which has been set to draft since then. This caused the image to not showing up in the API when used as featured image for a newer post.

@elyobo
Copy link

elyobo commented Jul 26, 2017

@rmccue can we reopen? There are plenty here that are seeing this and it seems like a cause has been identified as well.

I'm seeing exactly the same thing; a featured image was uploaded with a post, then reused as the featured image on another post and the original post was moved to the trash. The REST API refuses to embed the featured image correctly on the new post.

Somewhat related: https://core.trac.wordpress.org/ticket/30691

@rmccue
Copy link
Member

rmccue commented Jul 26, 2017

This repo is no longer used for tracking issues. If you're still experiencing this issue, please file it on Trac, or comment on an existing issue there.

@elyobo
Copy link

elyobo commented Jul 26, 2017

Thanks, will do. I've commented on that issue but that's not really the core focus of it, so I'll open another.

@elyobo
Copy link

elyobo commented Jul 26, 2017

Added as https://core.trac.wordpress.org/ticket/41445 if anyone else with the same issue wants to track progress on a fix.

@riobahtiar
Copy link

Hii All.. Any update for this issue.. because i get same issue.. 😢

@VictorPurMar
Copy link

Same here. I found this issue today after 1700 posts without any problem.

@VictorPurMar
Copy link

I found a solution for my case:

Its related with the media name (url) and and the special chars.
In my case was a jpg error. Some images make this error:

After a while i discover that is about the name of the pic, in my case:

PeñaNieto.jpg

The "ñ" and other special chars, could cause this error.

@elyobo
Copy link

elyobo commented Nov 10, 2017

Glad that worked for you @VictorPurMar, looks like you've found another cause for the problem.

There has been no progress on fixing the underlying issues covered in these reports

@StuartFeldt
Copy link

A patch has been submitted here: https://core.trac.wordpress.org/ticket/41445

@elyobo
Copy link

elyobo commented Feb 14, 2018

Thanks @StuartFeldt, nice to finally have a fix for this.

@besrabasant
Copy link

I found a solution for my case:

Its related with the media name (url) and and the special chars.
In my case was a jpg error. Some images make this error:

After a while i discover that is about the name of the pic, in my case:

PeñaNieto.jpg

The "ñ" and other special chars, could cause this error.

@VictorPurMar I agree with you. I had underscores and dashes in the image name. removed them and re-uploaded the image. Now its working fine.

@bengongon97
Copy link

bengongon97 commented Sep 19, 2018

Uh guys sorry but

I found a solution for my case:

Its related with the media name (url) and and the special chars.
In my case was a jpg error. Some images make this error:

After a while i discover that is about the name of the pic, in my case:

PeñaNieto.jpg

The "ñ" and other special chars, could cause this error.

Uh this is not the one that works, sorry. It is a very strange issue. I own the site "muharrir.net" which is a Turkish website. It hosts many Turkish-character-including names of images. We are developing an Android app for it and today suddenly we experience the crash. We were OMG-ed and tried the resolve the issue. The fastest workaround we could come up with was surrounding the processing code with:

if (code == null || !code.equals("rest_forbidden")) { //java code to process }

Plus, see the uploaded images. Both contains Turkish-specific characters like "ı" and/or "ş". "ŞU TARAFA DOĞRU" has no errors or crashes, I get the images perfectly. No code or error returns.

But the latest post that caused our app to crash has the issue. It has "ı"s all over. But I don't see any difference in both. Both contain non-ASCII characters anyway. It really looks like a random issue to me. Just FYI.

whatsapp image 2018-09-19 at 22 57 41
whatsapp image 2018-09-19 at 22 58 08

@elyobo
Copy link

elyobo commented Sep 19, 2018

@besrabasant the hashes and dashes are a red herring, it was the reuploading that fixed it for you - as described above, the problem is related to the permissions of the post it was originally uploaded against, uploading again to a different post will resolve the problem.

The underlying problem was identified and raised as an issue in WP's trac more than a year ago now, with a patch now available (but @StuartFeldt has not responded to the comments on the patch there yet) but not yet merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests