I'm working on a script to persistently save GitLab Issues (in my case requirements) as Markdown files in a repository with tags and as a compiled requirements document in PDF via GitLab CI. In addition, the script needs to download all attached sources (images, diagrams, PDF files, ...), so they can be version controlled too.
The script is written in Python 3.6 and uses python-gitlab to use the GitLab API v4.
After requesting the issue description text, it's scanned for image URLs of that form: 
. Each relative path is prepended by GitLab's host URL and handed over to urllib.urlretrieve
.
When running the request, I get HTTP 401 errors, because I'm not authenticated.
for image in images:
downloadURL = URL + image
imagePath = "" + image
print(" downloading '{fromURL}' to '{toPath}'".format(fromURL=downloadURL, toPath=imagePath))
try:
urlretrieve(downloadURL, imagePath)
except HTTPError as ex:
print(ex)
except FileNotFoundError as ex:
print(ex)
GitLab uses authentication via tokens. How can I use this authentication method with urllib
?
E.g. when I use Insomnia to execute JSON requests directly to GitLabs API, I use the Private-Token
HTTP header for authentication. Can I add this header to a urllib
call?