Repository: Flexget/Flexget

Issue:
filesystem plugin fails when encountering unusual characters in file name
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- 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!
--->

I see there is a bug reported about unicode characters leading to crash, but I don't think it's the same issue. This isn't about python3, and it's not about a crash, just a mishandling of (possibly unicode?) characters in a plugin. I think.

### Expected behaviour:
Expect filesystem plugin to handle files with untypical characters in file name

### Actual behaviour:
filesystem plugin fails to process files with certain characters in file name. In my experince: Apostroph (’) and japanese unicode characters. Probably quite a few other characters, too.

One might say that such characters shouldn't be used in file names (I'd agree with that!), but that's the file name provided for files from some trackers. Such trackers should perhaps be more conservative in their data output, but flexget should also be liberal in what data input it accepts.

### Steps to reproduce:
- Step 1: A torrent file exists in watchdir processed by filesystem plugin contains this character:  --> ’  <-- , say something like Artist - Artist's Album.torrent
- Step 2. Entry failes: <urlopen error [Errno 2] No such file or directory: '/home/username/watchdir/Artist - Artist\xc3\xa2\xc2\x80\xc2\x99s Album.torrent'>

#### Config:
```
PARTIAL config:
tasks:
  music-watchdir:
    filesystem:
      path: /home/username/watchdir
      mask: '*.torrent'
    set:
      path: /home/username/temp_downloads
      movedone: /home/username/downloads
      label: music
    accept_all: yes
    deluge:
      port: 6666


```
  
#### Log:
```
Too much private info in log
```

### Additional information:

- FlexGet version: 2.10.89 You are on the latest release.
- Python version: Python 2.7.9
- Installation method: pip
- Using daemon (yes/no): no
- OS and version: Debian stable
- Link to crash 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). Note that FlexGet is not supported for use with Python v3.0, 3.1, 3.2 or 3.6.
- 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.
--->

filesystem plugin fails when encountering unusual characters in file name
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- 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!
--->

I see there is a bug reported about unicode characters leading to crash, but I don't think it's the same issue. This isn't about python3, and it's not about a crash, just a mishandling of (possibly unicode?) characters in a plugin. I think.

### Expected behaviour:
Expect filesystem plugin to handle files with untypical characters in file name

### Actual behaviour:
filesystem plugin fails to process files with certain characters in file name. In my experince: Apostroph (’) and japanese unicode characters. Probably quite a few other characters, too.

One might say that such characters shouldn't be used in file names (I'd agree with that!), but that's the file name provided for files from some trackers. Such trackers should perhaps be more conservative in their data output, but flexget should also be liberal in what data input it accepts.

### Steps to reproduce:
- Step 1: A torrent file exists in watchdir processed by filesystem plugin contains this character:  --> ’  <-- , say something like Artist - Artist's Album.torrent
- Step 2. Entry failes: <urlopen error [Errno 2] No such file or directory: '/home/username/watchdir/Artist - Artist\xc3\xa2\xc2\x80\xc2\x99s Album.torrent'>

#### Config:
```
PARTIAL config:
tasks:
  music-watchdir:
    filesystem:
      path: /home/username/watchdir
      mask: '*.torrent'
    set:
      path: /home/username/temp_downloads
      movedone: /home/username/downloads
      label: music
    accept_all: yes
    deluge:
      port: 6666


```
  
#### Log:
```
Too much private info in log
```

### Additional information:

- FlexGet version: 2.10.89 You are on the latest release.
- Python version: Python 2.7.9
- Installation method: pip
- Using daemon (yes/no): no
- OS and version: Debian stable
- Link to crash 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). Note that FlexGet is not supported for use with Python v3.0, 3.1, 3.2 or 3.6.
- 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:
Can you paste the file name it crapped out on? 
Can you paste the file name it crapped out on? 

Resolving patch:
diff --git a/flexget/utils/requests.py b/flexget/utils/requests.py
--- a/flexget/utils/requests.py
+++ b/flexget/utils/requests.py
@@ -2,6 +2,7 @@
 from builtins import *  # noqa pylint: disable=unused-import, redefined-builtin
 from future.moves.urllib.request import urlopen
 from future.moves.urllib.parse import urlparse
+from future.utils import text_to_native_str
 
 import time
 import logging
@@ -139,7 +140,7 @@ def _wrap_urlopen(url, timeout=None):
 
     """
     try:
-        raw = urlopen(url, timeout=timeout)
+        raw = urlopen(text_to_native_str(url, encoding='utf-8'), timeout=timeout)
     except IOError as e:
         msg = 'Error getting %s: %s' % (url, e)
         log.error(msg)


Test patch: