From 9c82347d4768160d2d3c2016d5437313a812cabb Mon Sep 17 00:00:00 2001
From: Leonid Gorkin <regnull@gmail.com>
Date: Fri, 17 Nov 2023 07:50:18 -0500
Subject: [PATCH 1/6] Update yahoo.py

---
 backtrader/feeds/yahoo.py | 46 ++-------------------------------------
 1 file changed, 2 insertions(+), 44 deletions(-)

diff --git a/backtrader/feeds/yahoo.py b/backtrader/feeds/yahoo.py
index d9a05212a..fe3f612f3 100644
--- a/backtrader/feeds/yahoo.py
+++ b/backtrader/feeds/yahoo.py
@@ -225,19 +225,13 @@ class YahooFinanceData(YahooFinanceCSVData):
         Whether to use the dividend/split adjusted close and adjust all values
         according to it.
 
-      - ``urlhist``
-
-        The url of the historical quotes in Yahoo Finance used to gather a
-        ``crumb`` authorization cookie for the download
-
       - ``urldown``
 
         The url of the actual download server
 
       - ``retries``
 
-        Number of times (each) to try to get a ``crumb`` cookie and download
-        the data
+        Number of times (each) to try to download the data
 
       '''
 
@@ -245,7 +239,6 @@ class YahooFinanceData(YahooFinanceCSVData):
         ('proxies', {}),
         ('period', 'd'),
         ('reverse', False),
-        ('urlhist', 'https://finance.yahoo.com/quote/{}/history'),
         ('urldown', 'https://query1.finance.yahoo.com/v7/finance/download'),
         ('retries', 3),
     )
@@ -266,41 +259,7 @@ def start_v7(self):
         if self.p.proxies:
             sesskwargs['proxies'] = self.p.proxies
 
-        crumb = None
-        sess = requests.Session()
-        sess.headers['User-Agent'] = 'backtrader'
-        for i in range(self.p.retries + 1):  # at least once
-            resp = sess.get(url, **sesskwargs)
-            if resp.status_code != requests.codes.ok:
-                continue
-
-            txt = resp.text
-            i = txt.find('CrumbStore')
-            if i == -1:
-                continue
-            i = txt.find('crumb', i)
-            if i == -1:
-                continue
-            istart = txt.find('"', i + len('crumb') + 1)
-            if istart == -1:
-                continue
-            istart += 1
-            iend = txt.find('"', istart)
-            if iend == -1:
-                continue
-
-            crumb = txt[istart:iend]
-            crumb = crumb.encode('ascii').decode('unicode-escape')
-            break
-
-        if crumb is None:
-            self.error = 'Crumb not found'
-            self.f = None
-            return
-
-        crumb = urlquote(crumb)
-
-        # urldown/ticker?period1=posix1&period2=posix2&interval=1d&events=history&crumb=crumb
+        # urldown/ticker?period1=posix1&period2=posix2&interval=1d&events=history
 
         # Try to download
         urld = '{}/{}'.format(self.p.urldown, self.p.dataname)
@@ -323,7 +282,6 @@ def start_v7(self):
 
         urlargs.append('interval={}'.format(intervals[self.p.timeframe]))
         urlargs.append('events=history')
-        urlargs.append('crumb={}'.format(crumb))
 
         urld = '{}?{}'.format(urld, '&'.join(urlargs))
         f = None

From ee8f7f1b5f3a8966016fa1fdf6a98448fedb2160 Mon Sep 17 00:00:00 2001
From: Leonid Gorkin <regnull@gmail.com>
Date: Sun, 19 Nov 2023 09:57:05 -0500
Subject: [PATCH 2/6] fix yahoo bug

---
 backtrader/feeds/yahoo.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/backtrader/feeds/yahoo.py b/backtrader/feeds/yahoo.py
index fe3f612f3..19d05d65d 100644
--- a/backtrader/feeds/yahoo.py
+++ b/backtrader/feeds/yahoo.py
@@ -253,7 +253,6 @@ def start_v7(self):
             raise Exception(msg)
 
         self.error = None
-        url = self.p.urlhist.format(self.p.dataname)
 
         sesskwargs = dict()
         if self.p.proxies:

From 8166883451ed688db0722d4ae120f5a1050c0a9f Mon Sep 17 00:00:00 2001
From: Leonid Gorkin <regnull@gmail.com>
Date: Sun, 19 Nov 2023 09:59:18 -0500
Subject: [PATCH 3/6] update version

---
 backtrader/version.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backtrader/version.py b/backtrader/version.py
index 52d618f60..7b938bdab 100644
--- a/backtrader/version.py
+++ b/backtrader/version.py
@@ -22,6 +22,6 @@
                         unicode_literals)
 
 
-__version__ = '1.9.78.123'
+__version__ = '1.9.79.1'
 
 __btversion__ = tuple(int(x) for x in __version__.split('.'))

From 8aa0873a05d68bba9c6b50a803221ffeb40796d8 Mon Sep 17 00:00:00 2001
From: Leonid Gorkin <regnull@gmail.com>
Date: Sun, 19 Nov 2023 10:02:56 -0500
Subject: [PATCH 4/6] another fix

---
 backtrader/feeds/yahoo.py | 1 +
 backtrader/version.py     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/backtrader/feeds/yahoo.py b/backtrader/feeds/yahoo.py
index 19d05d65d..16d095b38 100644
--- a/backtrader/feeds/yahoo.py
+++ b/backtrader/feeds/yahoo.py
@@ -284,6 +284,7 @@ def start_v7(self):
 
         urld = '{}?{}'.format(urld, '&'.join(urlargs))
         f = None
+        sess = requests.Session()
         for i in range(self.p.retries + 1):  # at least once
             resp = sess.get(urld, **sesskwargs)
             if resp.status_code != requests.codes.ok:
diff --git a/backtrader/version.py b/backtrader/version.py
index 7b938bdab..1dbd3baea 100644
--- a/backtrader/version.py
+++ b/backtrader/version.py
@@ -22,6 +22,6 @@
                         unicode_literals)
 
 
-__version__ = '1.9.79.1'
+__version__ = '1.9.79.2'
 
 __btversion__ = tuple(int(x) for x in __version__.split('.'))

From 5896dbfd6a87a93e947362539602624c64012b95 Mon Sep 17 00:00:00 2001
From: Leonid Gorkin <regnull@gmail.com>
Date: Sun, 19 Nov 2023 10:20:49 -0500
Subject: [PATCH 5/6] now really fix yahoo download

---
 backtrader/feeds/yahoo.py | 1 +
 backtrader/version.py     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/backtrader/feeds/yahoo.py b/backtrader/feeds/yahoo.py
index 16d095b38..be25d195f 100644
--- a/backtrader/feeds/yahoo.py
+++ b/backtrader/feeds/yahoo.py
@@ -285,6 +285,7 @@ def start_v7(self):
         urld = '{}?{}'.format(urld, '&'.join(urlargs))
         f = None
         sess = requests.Session()
+        sess.headers['User-Agent'] = 'backtrader'
         for i in range(self.p.retries + 1):  # at least once
             resp = sess.get(urld, **sesskwargs)
             if resp.status_code != requests.codes.ok:
diff --git a/backtrader/version.py b/backtrader/version.py
index 1dbd3baea..23bfdfbe5 100644
--- a/backtrader/version.py
+++ b/backtrader/version.py
@@ -22,6 +22,6 @@
                         unicode_literals)
 
 
-__version__ = '1.9.79.2'
+__version__ = '1.9.79.3'
 
 __btversion__ = tuple(int(x) for x in __version__.split('.'))

From 6f3375057eadc2774c867b7aaf7196e0bae50064 Mon Sep 17 00:00:00 2001
From: Leonid Gorkin <regnull@gmail.com>
Date: Sun, 19 Nov 2023 10:52:34 -0500
Subject: [PATCH 6/6] update version

---
 backtrader/version.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backtrader/version.py b/backtrader/version.py
index 23bfdfbe5..5fc410b49 100644
--- a/backtrader/version.py
+++ b/backtrader/version.py
@@ -22,6 +22,6 @@
                         unicode_literals)
 
 
-__version__ = '1.9.79.3'
+__version__ = '1.9.78.124'
 
 __btversion__ = tuple(int(x) for x in __version__.split('.'))