Repository: Flexget/Flexget

Issue:
Unhandled error in plugin from_transmission
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- Is this an issue with webui? Make an issue over on https://github.com/Flexget/webui
- Did you recently upgrade? Look at the Change Log and Upgrade Actions to make sure that you don't need to make any changes to your config https://flexget.com/ChangeLog https://flexget.com/UpgradeActions
- Are you running FlexGet as a daemon? Stop it completely and then start it again https://flexget.com/CLI/daemon
- Did you search to see if the issue already exists? https://github.com/Flexget/Flexget/issues
- Did you fill out the issue template as completely as possible?

The issue template is here because it helps to ensure you submitted all the necessary information the first time, and allows us to more quickly review issues. Please fill it out correctly and do not ignore it, no matter how irrelevant you think it may be. Thanks in advance for your help with this!
--->

### Expected behavior:

Get the list of entries from the transmission.

### Actual behavior:

Unhandled error in plugin from_transmission.

### Steps to reproduce:
- Step 1: Upgrade to 3.1.92
- Step 2: Install transmission-rpc
- Step 3: Use from_transmission in task

#### Config:
``` yaml 
  TRANS_CLN:
    no_entries_ok: yes
    from_transmission:
      <<: *transmission_settings
      only_complete: yes
    disable: [seen, seen_info_hash, notify]
    if:
      - transmission_progress == 100: accept
      - not transmission_seed_ratio_ok: reject
      - not transmission_idle_limit_ok: reject
    transmission:
      <<: *transmission_settings
      action: remove
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
2020-12-28 14:15:51 CRITICAL task          TRANS_CLN       BUG: Unhandled error in plugin from_transmission: 'Client' object has no attribute 'http_handler'
Traceback (most recent call last):

  File "/usr/lib/python3.6/threading.py", line 884, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0xb6838c90>
    └ <Thread(task_queue, stopped daemon -1446013856)>
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0xb6838b70>
    └ <Thread(task_queue, stopped daemon -1446013856)>
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(task_queue, stopped daemon -1446013856)>
    │    │        │    └ ()
    │    │        └ <Thread(task_queue, stopped daemon -1446013856)>
    │    └ <bound method TaskQueue.run of <flexget.task_queue.TaskQueue object at 0xb16bfc10>>
    └ <Thread(task_queue, stopped daemon -1446013856)>

  File "/usr/local/lib/python3.6/dist-packages/flexget/task_queue.py", line 46, in run
    self.current_task.execute()
    │    │            └ <function Task.execute at 0xb5490738>
    │    └ <flexget.task.Task object at 0xaecb87f0>
    └ <flexget.task_queue.TaskQueue object at 0xb16bfc10>

  File "/usr/local/lib/python3.6/dist-packages/flexget/task.py", line 87, in wrapper
    return func(self, *args, **kw)
           │    │      │       └ {}
           │    │      └ ()
           │    └ <flexget.task.Task object at 0xaecb87f0>
           └ <function Task.execute at 0xb54906f0>

  File "/usr/local/lib/python3.6/dist-packages/flexget/task.py", line 722, in execute
    self._execute()
    │    └ <function Task._execute at 0xb54906a8>
    └ <flexget.task.Task object at 0xaecb87f0>

  File "/usr/local/lib/python3.6/dist-packages/flexget/task.py", line 688, in _execute
    self.__run_task_phase(phase)
    │                     └ 'input'
    └ <flexget.task.Task object at 0xaecb87f0>

  File "/usr/local/lib/python3.6/dist-packages/flexget/task.py", line 514, in __run_task_phase
    response = self.__run_plugin(plugin, phase, args)
               │                 │       │      └ (<flexget.task.Task object at 0xaecb87f0>, {'host': '192.168.0.250', 'port': 9091, 'username': 'tnt', 'password': 'fylhtq1973...
               │                 │       └ 'input'
               │                 └ <PluginInfo(name=from_transmission)>
               └ <flexget.task.Task object at 0xaecb87f0>

> File "/usr/local/lib/python3.6/dist-packages/flexget/task.py", line 547, in __run_plugin
    result = method(*args, **kwargs)
             │       │       └ {}
             │       └ (<flexget.task.Task object at 0xaecb87f0>, {'host': '192.168.0.250', 'port': 9091, 'username': 'tnt', 'password': 'fylhtq1973...
             └ <Event(name=plugin.from_transmission.input,func=on_task_input,priority=128)>

  File "/usr/local/lib/python3.6/dist-packages/flexget/event.py", line 20, in __call__
    return self.func(*args, **kwargs)
           │    │     │       └ {}
           │    │     └ (<flexget.task.Task object at 0xaecb87f0>, {'host': '192.168.0.250', 'port': 9091, 'username': 'tnt', 'password': 'fylhtq1973...
           │    └ <bound method PluginTransmissionInput.on_task_input of <flexget.plugins.clients.transmission.PluginTransmissionInput object a...
           └ <Event(name=plugin.from_transmission.input,func=on_task_input,priority=128)>

  File "/usr/local/lib/python3.6/dist-packages/flexget/plugins/clients/transmission.py", line 186, in on_task_input
    self.client.http_handler.set_authentication(
    │    └ <transmission_rpc.client.Client object at 0xae28ec50>
    └ <flexget.plugins.clients.transmission.PluginTransmissionInput object at 0xb16d38f0>

AttributeError: 'Client' object has no attribute 'http_handler'
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/flexget/task.py", line 547, in __run_plugin
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/flexget/event.py", line 20, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/flexget/plugins/clients/transmission.py", line 186, in on_task_input
    self.client.http_handler.set_authentication(
AttributeError: 'Client' object has no attribute 'http_handler'

```
</details>

### Additional information:

- FlexGet version: 3.1.92
- Python version: 3.6.9
- Installation method: pip
- Using daemon (yes/no): yes
- OS and version: Armbian Linux 4.19.62-sunxi
- Link to crash log: https://cdn.discordapp.com/attachments/536690097496784906/793099343199993886/crash_report.2020.12.28.141551281798.log

<!---
In config and debug/crash logs, remember to redact any personal or sensitive information such as passwords, API keys, private URLs and so on.

Please verify that the following data is present before submitting your issue:

- Link to a paste service or paste above the relevant config (preferably full config, including templates if present). Please make sure the paste does not expire, if possible.
- Link to a paste service or paste above debug-level logs of the relevant task/s (use `flexget -L debug execute --tasks <Task_name>`).
- FlexGet version (use `flexget -V` to get it).
- Full Python version, for example `2.7.11` (use `python -V` to get it). 
- Installation method (pip, git install, etc).
- Whether or not you're running FlexGet as a daemon.
- OS and version.
- Attach crash log if one was generated, in addition to the debug-level log. It can be found in the directory with your config file.
--->



Discussion:

Resolving patch:
diff --git a/flexget/plugins/input/plex.py b/flexget/plugins/input/plex.py
--- a/flexget/plugins/input/plex.py
+++ b/flexget/plugins/input/plex.py
@@ -113,9 +113,12 @@ def plex_get_globalaccesstoken(self, config):
         return globalaccesstoken
 
     def plex_get_accesstoken(self, config, globalaccesstoken=""):
-        accesstoken = ""
+        accesstoken = None
         if not globalaccesstoken:
             globalaccesstoken = self.plex_get_globalaccesstoken(config)
+        if config['server'] in ('localhost', '127.0.0.1'):
+            log.debug('Server using localhost. Global Token will be used')
+            return globalaccesstoken
         try:
             r = requests.get("https://my.plexapp.com/pms/servers?X-Plex-Token=%s" % globalaccesstoken)
         except requests.RequestException as e:
@@ -123,7 +126,7 @@ def plex_get_accesstoken(self, config, globalaccesstoken=""):
                                      "authentication-token: %s. (%s)" % (globalaccesstoken, e))
         dom = parseString(r.text)
         for node in dom.getElementsByTagName('Server'):
-            if node.getAttribute('address') == config['server']:
+            if config['server'] in (node.getAttribute('address'), node.getAttribute('localAddresses')):
                 accesstoken = node.getAttribute('accessToken')
                 log.debug("Got plextoken: %s" % accesstoken)
         if not accesstoken:
@@ -146,7 +149,7 @@ def on_task_input(self, task, config):
         entries = []
         if config['unwatched_only'] and config['section'] != 'recentlyViewedShows' and config['section'] != 'all':
             urlconfig['unwatched'] = '1'
-        if config['username'] and config['password'] and config['server'] != '127.0.0.1':
+        if config['username'] and config['password']:
             accesstoken = self.plex_get_accesstoken(config)
             log.debug("Got accesstoken: %s" % accesstoken)
             urlconfig['X-Plex-Token'] = accesstoken
@@ -311,4 +314,4 @@ def on_task_input(self, task, config):
 
 @event('plugin.register')
 def register_plugin():
-    plugin.register(InputPlex, 'plex', api_ver=2)
+    plugin.register(InputPlex, 'plex', api_ver=2)
\ No newline at end of file


Test patch: