Solution: An Unexpected HTTP Error occurred during the API request

Solution: An Unexpected HTTP Error occurred during the API request

Yesterday while I was busy updating a couple of my WordPress blogs, on one of the blogs I kept on getting an unexpected error when I was trying to add and update plugins – An unexpected HTTP Error occurred during the API request.

To be honest, I was totally baffled by this error as this was the first time I got the error. This was a really big problem because I wasn’t able to update or add any of the necessary plugins to make the WordPress website work.

Research research research

After searching and doing some research on ways to fix this error I realised that this was quite a common error and there are a lot of people who had this error before. All the fixes that I have found online was for WordPress versions prior to 3.0 and it involves editing the http.php file in the
wp-includes folder found on the root of your WordPress installation.

Here’s the fix that I have found. Find this code on-line no 223 in http.php in the wp-includes folder.

{code type=PHP}
‘timeout’ => apply_filters( ‘http_request_timeout’, 5);
{/code}

Replace that code with:

{code type=PHP}
‘timeout’ => apply_filters( ‘http_request_timeout’, 30);
{/code}

This will not work if you are running a WordPress version 3 or higher as the above code is not in the http.php file anymore but in the class-http.php file also found in the wp-includes folder.

By replacing the code above resolved the nasty HTTP error I was getting. Hope it works for you!

 

About: Anton Koekemoer

I am a social media strategist, digital marketing consultant and a ORM specialist with an emphasis on Web 2.0 technologies. I provide a range of consulting services to help businesses achieve success online. I focus on dynamic Web 2.0 (Social Media) and various other digital marketing strategies and solutions to get targeted and positive results.

 
 
   
 
 
  • Vipadam86

    i really tried it , changed the timeout to 30 but nothing happened , and this problem really worry me, can this problem caused from the host ?
    http://www.health2b.com

    • Aryawidityas

      It doesnt work in mine too…is there any other solution?

      cream office chair

      • http://www.facebook.com/rudiahlers Rudi Ahlers

        For anyone who’s still having this problem:

        Try changing your nameserver IP’s to a different upstream DNS server. If your upstream DNS server is either off, too slow or having problems then you’ll get this issue as well.

        ping api.wordpress.com and see how quickly you get a response. If it takes a while to start showing the IP address, or ping responses (even if the ping responses are fast) then the DNS server is problematic and should be changed

  • http://www.facebook.com/terrimae Terri-Mae Alexander

    Thank you! This really helped me!

    TM

    • http://www.antonkoekemoer.com AntonRSA

      I am glad it worked for you.

  • http://www.facebook.com/terrimae Terri-Mae Alexander

    This really helped me. Thank you

  • http://canslimindonesia.com Edsbali

    I have edited class-http.php and put 30 into ‘timeout’
    but it was not working.
    the error message “An Unexpected HTTP Error occurred during the API request.” keep occur

    • http://www.antonkoekemoer.com AntonRSA

      What is the URL of your site?  Have you tried any other solutions to fix the problem?

    • Dchavez2

      coud you explaing how you fix the problems with this menssage:An Unexpected HTTP Error occurred during the API request.
      I try install a new themes.
       Thank

  • Dchavez2

    i installing wordpress 3.2.1 i have this error when i try installs new themes
    An Unexpected HTTP Error occurred during the API request.
    please help me

    • http://www.antonkoekemoer.com AntonRSA

      Did you follow the solution as I explained in the post?

    • Dchavez2

      yes i follow the instruction, i changed the seting int class-http.php to 30 into timeout. but it was not working, it the same problems with Edsbali

  • http://twitter.com/MassolPanjava massol507

    hallo brother, on WordPress 3.1 or higher setting file on class-http.php
    oke thank you

  • http://twitter.com/MassolPanjava massol507

    WordPress 3.2.1 setting time out on file class-http.php
    Thank you
    http://massol507.wordpress.com

  • Pingback: Wordpress不能安装插件或主题 | {前端开发:科技交流网}