Python get request from a url with both %2F and '/' char auto replaces %2F with a '/' causing an error

Viewed 61

I'm trying to make a get request to download a file from a firebase storage url. I'm not experienced in python, this is the url :

https://firebasestorage.googleapis.com/v0/b/webqpm-client-dev.appspot.com/o/files%2Fdxf_exame.dxf?alt=media&token=01de6805-5deb-44ca-9e64-66b9789066a3

I need the url as is, without changing %2F to '/' and without changing '/' to %2F, but python automatically changes %2F into a '/' resulting in an response error 400, Invalid HTTP method/URL pair.

How would I go about doing that ?

1 Answers

Requests [cleans up the URL] while preparing a request, which is a problem if you want to literally send %2F instead of /. There's not really a way to disable this, but it is possible to change the request after it has been prepared:

session = requests.Session()
request = requests.Request(method="GET", url=someurl)
prepped = session.prepare_request(request)
prepped.url = someurl
response = self.session.send(prepped)

prepare_request cleans up the URL, but after that we can just set the URL again on the prepared request.

Related