7x11x13 / free-bandcamp-downloader

Get free/name your price music from Bandcamp in lossless quality
https://pypi.org/project/free-bandcamp-downloader/
19 stars 4 forks source link

HTTP 403 When Requesting Bandcamp #11

Closed yoshiyoshyosh closed 1 month ago

yoshiyoshyosh commented 1 month ago

Not sure when this started, since I haven't used this program for a while

$ ~/.local/python-venv/bin/bcdl-free -l https://lacheque.bandcamp.com -z 12345 -e auto -f FLAC --no-unzip -d lacheque.bandcamp.com/files/
INFO:httpx:HTTP Request: GET https://www.1secmail.com/api/v1/?action=getDomainList "HTTP/1.1 200 OK"
Traceback (most recent call last):
  File "/home/yosh/.local/python-venv/bin/bcdl-free", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/yosh/.local/python-venv/lib/python3.12/site-packages/free_bandcamp_downloader/__main__.py", line 513, in main
    downloader.download_label(arguments["-l"], arguments["--force"])
  File "/home/yosh/.local/python-venv/lib/python3.12/site-packages/free_bandcamp_downloader/__main__.py", line 367, in download_label
    r.raise_for_status()
  File "/home/yosh/.local/python-venv/lib/python3.12/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://lacheque.bandcamp.com/

line 367 is

    def download_label(self, url: str, force: bool = False):
        r = self.session.get(url)
        r.raise_for_status()

which is odd, since all that self.session is is... self.session = requests.Session()

...and if I make the request from my own python instance...

Python 3.12.4 (main, Jun  9 2024, 22:05:49) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import requests
 >>> s = requests.Session()
 >>> r = s.get('https://lacheque.bandcamp.com')
 >>> r.raise_for_status()
 >>> r
<Response [200]>

what's going on here?

7x11x13 commented 1 month ago

I'm not able to reproduce... does this happen with all URLs, or just that one?

yoshiyoshyosh commented 1 month ago

does this happen with all URLs, or just that one?

all urls. I thought it was my vpn at first, so I disabled it and tried again--no dice. again, extremely odd that it's only happening with free-bandcamp-downloader, and not a bare python instance

EDIT: actually, it appears to only be happening in my python venv, not my machine's python environment. I'm able to reproduce in a bare python environment inside the venv, but not outside of it. this is extra odd and definitely not an issue with free-bandcamp-downloader...

yoshiyoshyosh commented 1 month ago

It was urllib3. downgrading urllib3 from 2.2 to 1.26.x made it work again

related issue: https://github.com/urllib3/urllib3/issues/3439

closing since this isn't an issue with free-bandcamp-downloader

yoshiyoshyosh commented 1 month ago

actually, this might be able to be worked around in free-bandcamp-downloader with a requirements.txt to target <2

7x11x13 commented 1 month ago

I'd rather not pin an old urllib3 dependency for all platforms since this bug only affects people running NixOS (?), but we can add a note in the README telling NixOS users that they should install the old version of urllib3.

yoshiyoshyosh commented 1 month ago

I'm able to reproduce it on my distribution (void linux) inside a fresh python venv that's disconnected from the package manager. is it not reproducible for you with urllib 2.2.x?

7x11x13 commented 1 month ago

I'm not able to reproduce on Armbian with urllib3 2.2.2

7x11x13 commented 1 month ago

But I am able to reproduce on Mac...

7x11x13 commented 1 month ago

Fixed in v0.3.4

pquentin commented 3 weeks ago

Hello! urllib3 developer here. Bandcamp.com weirdly requires the TLS cipher suites that are used in urllib3 1.26.x, even if it does not use them. Here's the workaround to continue using urllib3 2.x: https://github.com/urllib3/urllib3/issues/3439#issuecomment-2306400349