We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Tasks failing after migration from cfscraper to cloudscraper
Since #2381 one of my tasks stopped returning new entries.
After checking the log I noticed `cloudscraper` returns a ReCaptcha related error during the `rmz` automatic url-rewrite (a problem `cfscrape` doesn't have).
Upon further investigation, it seems that `cloudscraper` has this issue when importing an existing requests session generated by Flexget, since removing the last `task.requests` (for testing purposes) from https://github.com/Flexget/Flexget/blob/a4037da07f7d7707650596670c467ab3b7e748c9/flexget/plugins/operate/cfscraper.py#L39 results in a successful processing of the task.

Another finding: Disabling `urlrewriting` also did not trigger a ReCaptcha error (therefore completing the task) even without meddling with any of Flexget's .py's, however it also doesn't return a download URL if [rmz.py](https://github.com/Flexget/Flexget/blob/master/flexget/components/sites/sites/rmz.py) is not processed.
### Expected behaviour:
Task returning proper entries with populated urls

### Actual behaviour:
Task failing due to `cloudscraper` bumping into ReCaptcha during `rmz`url-rewrite
### Steps to reproduce:
- Step 1: 
#### Config:
```
tasks:
  cftask:
    disable:
      - seen
      - seen_info_hash
      - retry_failed
      # - urlrewriting
    cfscraper: yes
    rss: http://rmz.cr/feed
    series:
      # Random entry from the feed below#
      - Days of our lives
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
$ flexget execute --tasks cftask
2019-05-09 00:34 VERBOSE  task_queue                   There are 1 tasks to execute. Shutdown will commence when they have completed.
2019-05-09 00:34 VERBOSE  details       cftask         Produced 100 entries.
2019-05-09 00:34 VERBOSE  series.db     cftask         identified by is currently on `auto` for Days of our lives. Multiple id types may be accepted until it locks in on the appropriate type.
2019-05-09 00:34 VERBOSE  task          cftask         ACCEPTED: `[RR/NF/UL/OL/CU] Days of our Lives S54E160 720p WEB HEVC x265-RMTeam (198MB)` by series plugin because choosing first acceptable match
2019-05-09 00:35 WARNING  urlrewriter   cftask         URL rewriting rmz failed: Captcha
2019-05-09 00:35 ERROR    entry         cftask         Failed [RR/NF/UL/OL/CU] Days of our Lives S54E160 720p WEB HEVC x265-RMTeam (198MB) (None)
2019-05-09 00:35 VERBOSE  task          cftask         FAILED: `[RR/NF/UL/OL/CU] Days of our Lives S54E160 720p WEB HEVC x265-RMTeam (198MB)` by urlrewriting plugin
2019-05-09 00:35 VERBOSE  details       cftask         Summary - Accepted: 0 (Rejected: 0 Undecided: 99 Failed: 1)
```
</details>

### Additional information:

- FlexGet version: 2.20.26
- Python version: 2.7.14
- Installation method: pip
- Using daemon (yes/no): yes
- OS and version: Windows 10 (1809)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `flexget/plugins/operate/cfscraper.py`
Content:
```
1 from __future__ import unicode_literals, division, absolute_import
2 from builtins import *  # noqa pylint: disable=unused-import, redefined-builtin
3 
4 import logging
5 
6 from flexget import plugin
7 from flexget.event import event
8 from flexget.utils.requests import Session
9 
10 log = logging.getLogger('cfscraper')
11 
12 
13 class CFScraper(object):
14     """
15     Plugin that enables scraping of cloudflare protected sites.
16 
17     Example::
18       cfscraper: yes
19     """
20 
21     schema = {'type': 'boolean'}
22 
23     @plugin.priority(253)
24     def on_task_start(self, task, config):
25         try:
26             import cloudscraper
27         except ImportError as e:
28             log.debug('Error importing cloudscraper: %s' % e)
29             raise plugin.DependencyError(
30                 'cfscraper', 'cloudscraper', 'cloudscraper module required. ImportError: %s' % e
31             )
32 
33         class CFScrapeWrapper(Session, cloudscraper.CloudScraper):
34             """
35             This class allows the FlexGet session to inherit from CloudScraper instead of the requests.Session directly.
36             """
37 
38         if config is True:
39             task.requests = CFScrapeWrapper.create_scraper(task.requests)
40 
41 
42 @event('plugin.register')
43 def register_plugin():
44     plugin.register(CFScraper, 'cfscraper', api_ver=2)
45
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/flexget/plugins/operate/cfscraper.py b/flexget/plugins/operate/cfscraper.py
--- a/flexget/plugins/operate/cfscraper.py
+++ b/flexget/plugins/operate/cfscraper.py
@@ -6,6 +6,7 @@
 from flexget import plugin
 from flexget.event import event
 from flexget.utils.requests import Session
+from collections import OrderedDict
 
 log = logging.getLogger('cfscraper')
 
@@ -36,6 +37,18 @@
             """
 
         if config is True:
+            task.requests.headers = (
+                OrderedDict(
+                    [
+                        ('User-Agent', task.requests.headers['User-Agent']),
+                        ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
+                        ('Accept-Language', 'en-US,en;q=0.5'),
+                        ('Accept-Encoding', 'gzip, deflate'),
+                        ('Connection',  'close'),
+                        ('Upgrade-Insecure-Requests', '1')
+                    ]
+                )
+            )
             task.requests = CFScrapeWrapper.create_scraper(task.requests)

{"golden_diff": "diff --git a/flexget/plugins/operate/cfscraper.py b/flexget/plugins/operate/cfscraper.py\n--- a/flexget/plugins/operate/cfscraper.py\n+++ b/flexget/plugins/operate/cfscraper.py\n@@ -6,6 +6,7 @@\n from flexget import plugin\n from flexget.event import event\n from flexget.utils.requests import Session\n+from collections import OrderedDict\n \n log = logging.getLogger('cfscraper')\n \n@@ -36,6 +37,18 @@\n             \"\"\"\n \n         if config is True:\n+            task.requests.headers = (\n+                OrderedDict(\n+                    [\n+                        ('User-Agent', task.requests.headers['User-Agent']),\n+                        ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),\n+                        ('Accept-Language', 'en-US,en;q=0.5'),\n+                        ('Accept-Encoding', 'gzip, deflate'),\n+                        ('Connection',  'close'),\n+                        ('Upgrade-Insecure-Requests', '1')\n+                    ]\n+                )\n+            )\n             task.requests = CFScrapeWrapper.create_scraper(task.requests)\n", "issue": "Tasks failing after migration from cfscraper to cloudscraper\nSince #2381 one of my tasks stopped returning new entries.\r\nAfter checking the log I noticed `cloudscraper` returns a ReCaptcha related error during the `rmz` automatic url-rewrite (a problem `cfscrape` doesn't have).\r\nUpon further investigation, it seems that `cloudscraper` has this issue when importing an existing requests session generated by Flexget, since removing the last `task.requests` (for testing purposes) from https://github.com/Flexget/Flexget/blob/a4037da07f7d7707650596670c467ab3b7e748c9/flexget/plugins/operate/cfscraper.py#L39 results in a successful processing of the task.\r\n\r\nAnother finding: Disabling `urlrewriting` also did not trigger a ReCaptcha error (therefore completing the task) even without meddling with any of Flexget's .py's, however it also doesn't return a download URL if [rmz.py](https://github.com/Flexget/Flexget/blob/master/flexget/components/sites/sites/rmz.py) is not processed.\r\n### Expected behaviour:\r\nTask returning proper entries with populated urls\r\n\r\n### Actual behaviour:\r\nTask failing due to `cloudscraper` bumping into ReCaptcha during `rmz`url-rewrite\r\n### Steps to reproduce:\r\n- Step 1: \r\n#### Config:\r\n```\r\ntasks:\r\n  cftask:\r\n    disable:\r\n      - seen\r\n      - seen_info_hash\r\n      - retry_failed\r\n      # - urlrewriting\r\n    cfscraper: yes\r\n    rss: http://rmz.cr/feed\r\n    series:\r\n      # Random entry from the feed below#\r\n      - Days of our lives\r\n```\r\n  \r\n#### Log:\r\n<details>\r\n <summary>(click to expand)</summary>\r\n\r\n```\r\n$ flexget execute --tasks cftask\r\n2019-05-09 00:34 VERBOSE  task_queue                   There are 1 tasks to execute. Shutdown will commence when they have completed.\r\n2019-05-09 00:34 VERBOSE  details       cftask         Produced 100 entries.\r\n2019-05-09 00:34 VERBOSE  series.db     cftask         identified by is currently on `auto` for Days of our lives. Multiple id types may be accepted until it locks in on the appropriate type.\r\n2019-05-09 00:34 VERBOSE  task          cftask         ACCEPTED: `[RR/NF/UL/OL/CU] Days of our Lives S54E160 720p WEB HEVC x265-RMTeam (198MB)` by series plugin because choosing first acceptable match\r\n2019-05-09 00:35 WARNING  urlrewriter   cftask         URL rewriting rmz failed: Captcha\r\n2019-05-09 00:35 ERROR    entry         cftask         Failed [RR/NF/UL/OL/CU] Days of our Lives S54E160 720p WEB HEVC x265-RMTeam (198MB) (None)\r\n2019-05-09 00:35 VERBOSE  task          cftask         FAILED: `[RR/NF/UL/OL/CU] Days of our Lives S54E160 720p WEB HEVC x265-RMTeam (198MB)` by urlrewriting plugin\r\n2019-05-09 00:35 VERBOSE  details       cftask         Summary - Accepted: 0 (Rejected: 0 Undecided: 99 Failed: 1)\r\n```\r\n</details>\r\n\r\n### Additional information:\r\n\r\n- FlexGet version: 2.20.26\r\n- Python version: 2.7.14\r\n- Installation method: pip\r\n- Using daemon (yes/no): yes\r\n- OS and version: Windows 10 (1809)\r\n\n", "before_files": [{"content": "from __future__ import unicode_literals, division, absolute_import\nfrom builtins import *  # noqa pylint: disable=unused-import, redefined-builtin\n\nimport logging\n\nfrom flexget import plugin\nfrom flexget.event import event\nfrom flexget.utils.requests import Session\n\nlog = logging.getLogger('cfscraper')\n\n\nclass CFScraper(object):\n    \"\"\"\n    Plugin that enables scraping of cloudflare protected sites.\n\n    Example::\n      cfscraper: yes\n    \"\"\"\n\n    schema = {'type': 'boolean'}\n\n    @plugin.priority(253)\n    def on_task_start(self, task, config):\n        try:\n            import cloudscraper\n        except ImportError as e:\n            log.debug('Error importing cloudscraper: %s' % e)\n            raise plugin.DependencyError(\n                'cfscraper', 'cloudscraper', 'cloudscraper module required. ImportError: %s' % e\n            )\n\n        class CFScrapeWrapper(Session, cloudscraper.CloudScraper):\n            \"\"\"\n            This class allows the FlexGet session to inherit from CloudScraper instead of the requests.Session directly.\n            \"\"\"\n\n        if config is True:\n            task.requests = CFScrapeWrapper.create_scraper(task.requests)\n\n\n@event('plugin.register')\ndef register_plugin():\n    plugin.register(CFScraper, 'cfscraper', api_ver=2)\n", "path": "flexget/plugins/operate/cfscraper.py"}], "after_files": [{"content": "from __future__ import unicode_literals, division, absolute_import\nfrom builtins import *  # noqa pylint: disable=unused-import, redefined-builtin\n\nimport logging\n\nfrom flexget import plugin\nfrom flexget.event import event\nfrom flexget.utils.requests import Session\nfrom collections import OrderedDict\n\nlog = logging.getLogger('cfscraper')\n\n\nclass CFScraper(object):\n    \"\"\"\n    Plugin that enables scraping of cloudflare protected sites.\n\n    Example::\n      cfscraper: yes\n    \"\"\"\n\n    schema = {'type': 'boolean'}\n\n    @plugin.priority(253)\n    def on_task_start(self, task, config):\n        try:\n            import cloudscraper\n        except ImportError as e:\n            log.debug('Error importing cloudscraper: %s' % e)\n            raise plugin.DependencyError(\n                'cfscraper', 'cloudscraper', 'cloudscraper module required. ImportError: %s' % e\n            )\n\n        class CFScrapeWrapper(Session, cloudscraper.CloudScraper):\n            \"\"\"\n            This class allows the FlexGet session to inherit from CloudScraper instead of the requests.Session directly.\n            \"\"\"\n\n        if config is True:\n            task.requests.headers = (\n                OrderedDict(\n                    [\n                        ('User-Agent', task.requests.headers['User-Agent']),\n                        ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),\n                        ('Accept-Language', 'en-US,en;q=0.5'),\n                        ('Accept-Encoding', 'gzip, deflate'),\n                        ('Connection',  'close'),\n                        ('Upgrade-Insecure-Requests', '1')\n                    ]\n                )\n            )\n            task.requests = CFScrapeWrapper.create_scraper(task.requests)\n\n\n@event('plugin.register')\ndef register_plugin():\n    plugin.register(CFScraper, 'cfscraper', api_ver=2)\n", "path": "flexget/plugins/operate/cfscraper.py"}]}