1

I have a problem !

I work on gitlab UI on python.

I try to connect to gitlab like this:

import requests
import gitlab

GITLAB_URL = 'MY_GITLAB_URL'
PERSONAL_TOKEN = 'MY_PERSONAL_TOKEN'
PROXIES = {"http": "myProxy:8080",
           "https": "myProxy:8080"
           }

def git_connection():
    try:
        session = requests.Session()
        session.proxies.update(PROXIES)
        gl = gitlab.Gitlab(
            GITLAB_URL, private_token=PERSONAL_TOKEN, session=session)
        gl.auth()
        print("GitLab connection successful", flush=True)  # Debug message
        return gl
    except Exception as e:
        # Debug message
        print(f"Error connecting to GitLab: {e}", flush=True)
        return None
git_connection()

Code returns Error connecting to GitLab: HTTPSConnectionPool(host='MY_GITLAB_URL', port=443): Max retries exceeded with url: /api/v4/user (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 502 badgateway')))

But with curl command

curl -v -x "myProxy:8080" -X GET "MY_GITLAB_URL" -H "PRIVATE-TOKEN: MY_PERSONAL_TOKEN"

All is good !

Can you help me please ?

Thanks, Philippe (France)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.