Curl works perfectly in git bash. Problem is when I want to use python… Requests is not working for me.
See below
curl -u “USER:PASS” -L -O https://api.bitbucket.org/2.0/repositories/EEEE/AAA/downloads/zip.zip
But how can I mimic this with requests. Can this be done?
import requests
from requests.auth import HTTPBasicAuth
url = "https://bitbucket.org/SYA/Music/downloads/SSR131.zip"
src = r"C:\1\1\SR131.zip"
headers = {'Content-Type': 'application/json'}
respo = requests.get(url, stream=True, verify=False, auth=('##############', '######################'), headers=headers)
if respo.status_code == requests.codes.ok:
out = open(src, "wb")
for block in respo.iter_content(1024):
if not block:
break
out.write(block)
out.close()
else:
print("Not able to download ZIP url {url}: {status}, {content}".format(url=url, status=respo.status_code, content=respo.content))
Error:
Not able to download ZIP url https…: 401, b’’
More specifically:
Debug output of Requests:
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.bitbucket.org
C:\Users\Imapotatofish\AppData\Local\Continuum\miniconda3\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
send: b'GET /2.0/repositories/Imapotatofish/EEE/downloads/zip.zip HTTP/1.1\r\nHost: api.bitbucket.org\r\nUser-Agent: python-requests/2.18.4\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Basic ABC123REDACTED\r\n\r\n'
InsecureRequestWarning) repositories/EEEE/AAA/downloads/zip.zi
DEBUG:urllib3.connectionpool:https://api.bitbucket.org:443 "GET /2.0/repositories/Imapotatofish/EEE/downloads/zip HTTP/1.1" 401 0
reply: 'HTTP/1.1 401 Unauthorized\r\n'
header: Server header: WWW-Authenticate header: Content-Type header: Strict-Transport-Security header: Date header: X-Served-By header: X-Static-Version header: ETag header: X-Render-Time header: Connection header: X-Version header: X-Request-Count header: X-Frame-Options header: Content-Length Not able to download ZIP url https://api.bitbucket.org/2.0/repositories/Imapotatofish/EEE/downloads/zip: 401, b''