Closed vipera7 closed 4 years ago
You can catch the Transmission\Exception\NetworkException
instead of just the Exception
in your try catch.
I did as you said but the issue is still the same :
<?php
require 'vendor/autoload.php';
try{
$transmission = new Transmission\Client($hostname, $port, $username, $password, $httpClientBuilder = null);
} catch (Transmission\Exception\NetworkException $e) {
echo "Remote access is diabled";
}
What is the error?
@irazasyed I'm still getting :
<br />
<b>Fatal error</b>: Uncaught Transmission\Exception\NetworkException: 403: Forbidden - Your IP Address is Not Whitelisted in /php-transmission-sdk/src/Exception/NetworkException.php:82
Stack trace:
#0 /php-transmission-sdk/src/HttpClient/Plugin/ExceptionThrower.php(44): Transmission\Exception\NetworkException::createByCode(403, '403: Forbidden ...')
#1 /php-transmission-sdk/vendor/php-http/httplug/src/Promise/HttpFulfilledPromise.php(34): Transmission\HttpClient\Plugin\ExceptionThrower->Transmission\HttpClient\Plugin\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /php-transmission-sdk/src/HttpClient/Plugin/ExceptionThrower.php(48): Http\Client\Promise\HttpFulfilledPromise->then(Object(Closure))
#3 /php-transmission-sdk/vendor/php-http/client-common/src/PluginClient.php(132): Transmission\HttpClient\Plugin\ExceptionThrower->handleRequest(Object(Nyholm\Psr7\Request), O in <b>/php-transmission-sdk/src/Exception/NetworkException.php</b> on line <b>82</b><br />
I made the error (403) for testing purpose.
I also tried with the backslash :
try{
$transmission = new Transmission\Client($hostname, $port, $username, $password, $httpClientBuilder = null);
} catch (\Transmission\Exception\NetworkException $e) {
$result = array("Error" => "Remote access is disabled");
}
PHP 7.3.11
~I just realized it's a fatal error and you can't catch fatal errors in PHP since it stops the execution of the script. There are workarounds like registering your custom handler in shutdown or log, etc. but otherwise there is no way.~
~You should make sure you have remote access.~
Nevermind, I just tested this code and it works fine for me (I'm able to catch the exception).
<?php
require __DIR__.'/vendor/autoload.php';
use Transmission\Client;
use Transmission\Exception\NetworkException;
$hostname = '127.0.0.1';
$port = 9091;
$username = 'username';
$password = 'password';
try{
$transmission = new Client($hostname, $port, $username, $password);
$result = $transmission->get(); // Get All Torrents.
var_dump($result);
} catch (NetworkException $e) {
echo $e->getMessage();
}
Also, in addition to that. In PHP 7 onwards, you can use \Throwable
to catch such kinda errors too. So if it still fails for whatever reasons, try that instead. Hope that helps!
Detailed description
When I'm trying to connect to a remote transmission, I'm getting the following error:
Possible implementation
I tried something like that (but doesn't work):
I also tried :
Thanks for any help