• I installed a theme for WP that uses wp_remote_get() to import demo data. It reports that wp_remote_get fails with error 401.

    I have checked to see if php curl is enabled at the hosting provider. It is. So that is not causing the error.

    Is there something more I can do to be able to find the reason for this error?

    BR,
    Johan

Viewing 8 replies - 1 through 8 (of 8 total)
  • Howdy @johanklinge,

    Without seeing any of the code, I can only make assumptions but the 401 means there was some kind of authentication that was not successful. Is this a commercial theme? I would contact the theme developer(s) and let them know their remote request is failing. If you visit the URL that it is trying to retrieve data from, are you prompted for some kind of HTTP Authentication? If so, is the wp_remote_get() properly passing along those credentials?

    Thread Starter johanklinge

    (@johanklinge)

    Hi and thanks for the reply.

    I think I am on to the answer. I am just setting up the site and while it is under construction I put a login with Basic HTTP Authorization on the entire wordpress directory. I guess this is what causes the problems..

    Will try to look inte the documentation for wp_remote_get to see if I can add the login to the call and see if that helps.

    BR, Johan

    That could be your issue. If you temporarily turn the HTTP Auth off and try to import again, does it work? If a one-time demo data import is the only issue you are having, I would probably just do that and then place the authentication back right after.

    Will try to look inte the documentation for wp_remote_get to see if I can add the login to the call

    Just FYI, I believe you’ll have to use wp_remote_request() to pass along Basic HTTP Authentication headers with your requests.

    Thread Starter johanklinge

    (@johanklinge)

    Hi Craig,

    Thanks! I tested and turning HTTP Auth of removed the error from wp_remote_get.

    I found some example code like this:

    $http_basicauth_args = array(
       'headers' => array(
           'Authorization' => 'Basic ' . base64_encode( $http_username . ':' .
                               $http_password )
        )
    );
    $file_data = wp_remote_get( $file_path, $http_basicauth_args  );

    I tested that and it seems to solve the problem. At least the error code I was getting earlier disappears. But since I’m new to this and have no good way of debugging WordPress code to see what is really happening it is hard to say for sure ??

    Still – removing HTTP Auth while importing demo content is a workable solution! Also I spoke to the theme authors who are considering adding support for HTTP Auth in their import function..

    @johan I seem to be having this same problem. But oddly, it was working fine then today I’m getting the error.
    I’ve tried disabling all the plugins. nothing changed.
    deleting the plugins. also no change
    deleted and reinstalled wordpress with theme, same thing…
    I thought it might have been something to do with wordfence plugin but since i fresh installed minimalistically I figured that would fix it but still no progress…

    How did you go about this?

    Thread Starter johanklinge

    (@johanklinge)

    My problem came from my site being in a folder protected by HTTP Basic Authentication (https://en.wikipedia.org/wiki/Basic_access_authentication). The theme (BeTheme) did not have funcations to handle importing demo data when the site was set up this way. I think the developers added this functionality in a later version.

    If your problem is relating to something else I do not know how to solve it.

    BR, Johan

    Hi,

    I have the same problem on the same damn theme….can you please tell me what files you edited as a work around?

    Or make a more step by step fix cause i am not that technical when it comes to code!

    The thing is…it works on the same server but another domain…no error…I really dot get how is that possible…

    Thread Starter johanklinge

    (@johanklinge)

    @qstarw Do you have your site in a directory on the server that is password protected? Because that was what was causing the issues for me.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘wp_remote_get fail’ is closed to new replies.