1

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?

Willy
  • 9,848
  • 22
  • 141
  • 284
  • If you are unsure why a requests works using client1 but not client2 then I would recommend to redirect both through a proxy like mitmproxy so you can see the actual request and compare the differences. – Robert May 08 '23 at 11:22
  • Finally I got it by replacing http.client.HTTPConnection by http.client.HTTPSConnection (secure) – Willy May 08 '23 at 11:25

1 Answers1

0

Finally I got it by replacing:

http.client.HTTPConnection

to

http.client.HTTPSConnection

Willy
  • 9,848
  • 22
  • 141
  • 284