Zend_Service_Yahoo showing sending request error. Status code: 404 - zend-framework

I need your help.
I am facing a problem using Zend_Service_Yahoo.
I am trying to use Zend_Service_Yahoo. But it shows
"An error occurred sending request. Status code: 404"
$yahoo = new Zend_Service_Yahoo("YAHOO_APPLICATION_ID");
try{
$results = $yahoo->imageSearch('PHP');
foreach ($results as $result) {
echo $result->Title . '<br />';
}
}catch(Exception $e){
echo $e->getMessage();
}
Reference : http://framework.zend.com/manual/1.0/en/zend.service.yahoo.html
Thanks in advance

That's because imagesearch has been deprecated.
We’re shutting down this service in April 2011. For further details, please see the Deprecated Services blog post.

Related

Error code 500: Internal server error (ReactPHP)

I tried to make a server file for my ReactPHP app following this video but when I started up the server, it ran successfully, but when I made a simple http GET the response was "Error code
500: Internal server error", when in theory it should've returned a JSON {"message": "Hello"}.
Here is the code for the server.php file:
use React\Http\Server;
use React\Http\Response;
use Psr\Http\Message\ServerRequestInterface;
use \React\EventLoop\Factory;
require 'vendor/autoload.php';
$loop = Factory::create();
$server = new Server(function (ServerRequestInterface $request) {
return new Response(
200, ['Content-Type' => 'application/json'], json_encode(['message' => 'Hello'])
);
});
$socket = new \React\Socket\Server('127.0.0.1:8000', $loop);
$server->listen($socket);
echo "Listening on ".str_replace('tcp', 'http', $socket->getAddress()). PHP_EOL;
$loop->run();
request.http file:
GET 127.0.0.1:8000
What the request has returned:
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain
Server: ReactPHP/1
Date: Fri, 20 Aug 2021 09:03:19 GMT
Content-Length: 32
Connection: close
Error 500: Internal Server Error
Can someone say to me what the problem is? I think I miswrote something in the server.php file but I am not the one to tell
Code you use from a video is a bit outdated.
If you need a quickfix - just replace one line and it will work:
--- use React\Http\Response;
+++ use React\Http\Message\Response;
Working code for this example (as for react/http-1.5.0) would be
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Loop;
use React\Http\HttpServer;
use React\Http\Message\Response;
use React\Socket\SocketServer;
require_once __DIR__ . '/vendor/autoload.php';
$loop = Loop::get();
$server = new HttpServer(function (ServerRequestInterface $request) {
return new Response(
200, ['Content-Type' => 'application/json'], json_encode(['message' => 'Hello'])
);
});
$socket = new SocketServer('127.0.0.1:8000');
$server->listen($socket);
echo 'Listening on ' . str_replace('tcp', 'http', $socket->getAddress()) . PHP_EOL;
$loop->run();
List of changes:
Response class location (actual fix)
loop factory changed, deprecation upFactory::create() -> Loop::get
http-server changed React\Http\Server -> React\Http\HttpServer
socket-server changed React\Socket\Server -> React\Socket\SocketServer
The answer provided by Ilya Urvachev is the right one, basically react evolved and the Response class is not located in the same location anymore.
Overall after instantiating your server I recommend you to use this line of code so you get error messages in your command line interface:
$server->on('error', function (Exception $exception) {
echo $exception->getMessage() . PHP_EOL;
});
All in all, It's been very difficult for me to move from regular PHP to reactphp, which completely destroy the verbosity of error messages. Ie. You've got exception telling you that the format of the answer is not the expected one, while, what really fucks up your code is that have an error in the syntax of one of your MySQL queries, which sends back a message that is not respecting the expecting answer's format. If someone wants to provide additional way to improve the reactphp verbosity, feel free :)

Powershell - Querying URL with login and returning HTTP Status

I'm using a standard [System.Net.WebRequest] class to return the HTTP response code of a given URL.
The URL points to an internal web application server, which returns a "401 Unauthorised" error. This is actually OK as the service account running the script doesn't have a valid account to the application. However, I am more interested that the website is responding. However, I assumed that this is a HTTP Response in itself so I could manage this, but instead it returned as a null value.
$HTTP_Request = [System.Net.WebRequest]::Create('http://google.com')
$HTTP_Response = $HTTP_Request.GetResponse()
$HTTP_Status = [int]$HTTP_Response.StatusCode
Exception calling "GetResponse" with "0" argument(s): "The remote
server returned an error: (407) Proxy Authentication Required."
(I'm using Google in this example, which our servers are blocked from accessing external sites).
So I can't get as far as $HTTP_Status = [int]$HTTP_Response.StatusCode in the code because it won't accept 400 errors as a code.
How can I accept a 401 (or 407 in this example) in the query?
Thanks
Got it!
try{
$request = $null
$request = Invoke-WebRequest -Uri "<URL>"
}
catch
{
$request = $_.Exception.Response
}
$StatusCode = [int] $request.StatusCode;
$StatusDescription = $request.StatusDescription;
You could've done:
$HTTP_Request = [System.Net.WebRequest]::Create('http://google.com')
$HTTP_Request.Method = "GET"
$HTTP_Request.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[System.Net.HttpWebResponse]$HTTP_Response = $HTTP_Request.GetResponse()
Try {
$HTTP_Status = [int]$HTTP_Response.StatusCode
}
Catch {
#handle the error if you like, or not...
}
If ($HTTP_Status -eq 200) {
Write-Host "Good Response"
} Else {
Write-Host "Site Down or Access Denied"
}
# If you got a 404 Not Found, the response will be null so can't be closed
If ($HTTP_Response -eq $null) { } Else { $HTTP_Response.Close() }
You were missing the authentication piece:
$HTTP_Request.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
I re-read your post and because your service account did not have access to the URL you are hitting (which was not actually google.com... you should've put myserver.com...grr), you would never actually get a 200, but always will get an exception. This is a bad practice, because instead of looking for the 200, you would have to always look for the 401 or 407 Unauthorized exception status code specifically, and if the code/response changed to something else, only then is it considered a failure - but technically it always had been a failure, because it never reached the site! It masks potential issues if you intend to go on deliberately using a site your service account doesn't have access to reach. And if your service account was ever granted access, your code would have to be updated.

Getting HTTP response from balanced

If I am using PHP code such as
$card = Balanced\Card::get("/v1/marketplaces/TEST-MP4K6K0PWGyPtXL4LZ42sQSb/cards/CC5N3HHUDrAyvhNwQOoUd3UX");
$card->unstore();
or
$customer->addCard($card)
how do I read the HTTP response from balanced to know if it has worked or what the error is?
The Balanced client libraries are written so that they will throw exceptions if there is a non 2xx HTTP response from the API.
The correct way to tell if the addCard operation failed for example would be to write some code that looks like
try {
$customer->addCard($card)
} catch (Balanced\Error $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

I am getting an error from Facebook in my application

I am creating an image from my Facebook application. I am getting the following error from Facebook.
CurlException: 56: SSL read: error:00000000:lib(0):func(0):reason(0),
errno 104
Is there anything wrong in my code?
Without looking at your code, or knowing if there is an actual issue w/ your SSL certificate (which you should NOT ignore), try something like this as a workaround:
<?php
$retry=False;
do {
try {
//your code goes here
$retry=False;
}
catch (Exception $e) {
echo $e->getMessage(), "\n";
$retry=True;
}
}
while ($retry);
?>

SoapClient error fallback in PHP

In PHP, if you try to instantiate a new SoapClient, and the WSDL is not accessible (server down or whatever), a PHP fatal error is thrown:
Fatal error: SOAP-ERROR: Parsing WSDL:
Couldn't load from
'http://example.com/servlet/app/SomeService?wsdl'
: failed to load external entity
"http://example.com/servlet/app/SomeService?wsdl"
Fatal errors in PHP, as far as I know, are not recoverable.
Is there any way to fallback from this? Can this fatal error somehow be avoided?
Edit: I should say that I am running on PHP 5.2, if it makes any difference.
This has already been discussed :
https://bugs.php.net/bug.php?id=47584
http://www.php.net/manual/en/class.soapclient.php#104046
Rasmus himself proposed the following solution:
<?php
try {
$x = #new SoapClient("non-existent.wsdl",array("exceptions" => 1));
} catch (SoapFault $E) {
echo $E->faultstring;
}
echo "ok\n";
See this topic How do I catch a PHP Fatal Error
Basically you cant recover from a fatal error but you can provide a better experience to the user when registering a shutdown function
register_shutdown_function('handleShutdown');
function handleShutdown(){
$error = error_get_last();
if($error !== NULL){
echo "Sorry for the inconvenience, an error just occurred.";
}
}