Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 Client Error: Forbidden for url: https://www.billboard.com/charts/radio-songs #97

Open
keyreel opened this issue Oct 9, 2024 · 5 comments

Comments

@keyreel
Copy link

keyreel commented Oct 9, 2024

The code:

import billboard
name = 'radio-songs'
chart = billboard.ChartData(name, date=None, year=None, fetch=True, timeout=25)
print(chart.title)

raise

Traceback (most recent call last):
  File "test2.py", line 4, in <module>
    chart = billboard.ChartData(name, date=None, year=None, fetch=True, timeout=25)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv\Lib\site-packages\billboard.py", line 192, in __init__
    self.fetchEntries()
  File ".venv\Lib\site-packages\billboard.py", line 501, in fetchEntries
    req.raise_for_status()
  File ".venv\Lib\site-packages\requests\models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://www.billboard.com/charts/radio-songs

Process finished with exit code 1

Python 3.12
Billboard.py 7.1.0
Requests 2.32.3

@keyreel
Copy link
Author

keyreel commented Oct 16, 2024

Does anyone have this error? Or is it just me?

@johnwmillr
Copy link
Collaborator

When I visit the Radio Songs chart, I see that the chart is only available to "Pro subscribers". We'd have to add support for paid billboard subscription accounts (and you'd have to pay for their subscription) for this link to work.

@keyreel
Copy link
Author

keyreel commented Oct 31, 2024

I think that this is not the case. I got an error requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://www.billboard.com/charts/radio-songs, that mean that the page is not loaded. When I get the page in a browser the result depends on what adblock and browser I've using. Sometime I get full chart, sometime I get message about 'pro subscribing', but whole chart is loaded in both case (when I get subscribing offer, it shows just 1st position and just hide the rest of the chart).
I think that the reason is in the headers that requests module sends.
Anybody have any suggestions?

@keyreel
Copy link
Author

keyreel commented Oct 31, 2024

Using Debug tool in the PyCharm I've changed User-Agent from 'python-requests/2.32.3' to 'Mozilla/5.0' and got a result.
Anybody know how to change default User-Agent?

@keyreel
Copy link
Author

keyreel commented Oct 31, 2024

Adding session.headers.update({'User-Agent': 'Mozilla/5.0'}) to the line 509 of the billboard.py:

def _get_session_with_retries(max_retries):
    session = requests.Session()
    session.headers.update({'User-Agent': 'Mozilla/5.0'}) # Added to change User-Agent
    session.mount(
        "https://www.billboard.com",
        requests.adapters.HTTPAdapter(max_retries=max_retries),
    )
    return session

makes module working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants