title: Yahoo finance API gives error 403 (forbidden) on old URL and User-Agent
body: <p>One of the use cases I use Yahoo finance API for is to find out the earnings date for a given stock. This was working fine till about 7/2021 but started giving error 403 (forbidden).</p>
  <p>After struggling a while, found that adding a <code>{'User-agent': 'Mozilla/5.0'}</code> header would fix the issue. If you face a similar issue, you could try and see if it fixes for you too. Here is a sample screenshot:</p>
  <pre><code>&gt;&gt;&gt; url=&quot;https://query2.finance.yahoo.com/v10/finance/quoteSummary/PYPL?modules=calendarEvents&quot;
  &gt;&gt;&gt; r=requests.get(url)
  &gt;&gt;&gt; r
  &lt;Response [403]&gt;
  &gt;&gt;&gt; r=requests.get(url, headers={'User-agent': 'Mozilla/5.0'})
  &gt;&gt;&gt; r
  &lt;Response [200]&gt;
  &gt;&gt;&gt; r.json()
  {'quoteSummary': {'result': [{'calendarEvents': {'maxAge': 1, 'earnings': {'earningsDate': [{'raw': 1635764340, 'fmt': '2021-11-01'}, {'raw': 1636113600, 'fmt': '2021-11-05'}], 'earningsAverage': {'raw': 1.13, 'fmt': '1.13'}, 'earningsLow': {'raw': 0.97, 'fmt': '0.97'}, 'earningsHigh': {'raw': 1.27, 'fmt': '1.27'}, 'revenueAverage': {'raw': 6265160000, 'fmt': '6.27B', 'longFmt': '6,265,160,000'}, 'revenueLow': {'raw': 6041000000, 'fmt': '6.04B', 'longFmt': '6,041,000,000'}, 'revenueHigh': {'raw': 6539200000, 'fmt': '6.54B', 'longFmt': '6,539,200,000'}}, 'exDividendDate': {}, 'dividendDate': {}}}], 'error': None}}
  
  </code></pre>