How to check if a release exists on a GitLab repo

421 views Asked by At

I have a repo in GitLab and now I need to check if a release based on a tag exists using Python.

I have tried below Python code but I always get the response "301 Moved Permanently" independently if release exsits or not.

I am using Http Client instead of requests as I do not want to depend on any third-party and also because Http Client is faster.

conn = http.client.HTTPConnection("my.git.space")

headers = { 'PRIVATE-TOKEN': "XXX" }

conn.request("GET", "/api/v4/projects/497/releases/1.0.0.0", headers=headers)
res = conn.getresponse()

print(f"{res.status} {res.reason}")

conn.close()

If I use postman it works, if exists it returns 200, otherwise, 404.

Any ideas on how to do this?

1

There are 1 answers

1
Willy On BEST ANSWER

Finally I got it by replacing:

http.client.HTTPConnection

to

http.client.HTTPSConnection