Skip to content

Allow redirects when making Gitlab requests

Yoann Schneider requested to merge allow-redirects-gitlab-auth into master

When I tried to use the new auth in a real Gitlab CI, I got HTTP 302 errors. This indicates a redirection but the requests call we currently doesn't allow that.

I tested the call in the job with redirects allowed and it works perfectly. You can also use the script below to reproduce the issue.

Click to expand
import requests
import os
from requests.compat import urljoin

for allow in (False, True):
    print(f"Allow_redirects: `{allow}`")
    print(
        requests.get(
            urljoin(
                os.getenv("CI_API_V4_URL"),
                f"projects/{os.getenv('CI_PROJECT_ID')}/secure_files",
            ),
            headers={"PRIVATE-TOKEN": os.getenv("GITLAB_TOKEN")},
            allow_redirects=allow,
        )
    )
    print()
Allow_redirects: `False`
<Response [302]>

Allow_redirects: `True`
<Response [200]>

Merge request reports

Loading