Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,898
Community Members
 
Community Events
185
Community Groups

HTTP 406 error when calling 'Get log file for a step' Bitbucket Pipelines API

When running the following code, as per this link:

import requests
import os

workspace = "redacted"
repo_slug = "redacted"
token = os.getenv('BB_TOKEN')
pipeline_uuid = "{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee}"
step_uuid = "{ffffffff-gggg-hhhh-iiii-jjjjjjjjjjjj}"

url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines/{pipeline_uuid}/steps/{step_uuid}/log"

headers = {"Accept": "application/json", "Authorization": f"Bearer {token}"}
response = requests.request("GET", url, headers=headers)

print(response.text)

I get the following:

{"code": 406, "message": "HTTP 406 Not Acceptable"}

The pipeline_uuid and step_uuid are 100% correct (obviously altered in these examples).

By comparison, the following script works perfectly - the only difference is the url:

import requests
import json

workspace = "redacted"
repo_slug = "redacted"
token = os.getenv('BB_TOKEN')
pipeline_uuid = "{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee}"

url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines/{pipeline_uuid}/steps/"

headers = {"Accept": "application/json", "Authorization": f"Bearer {token}"}
response = requests.request("GET", url, headers=headers)

print(response.txt)

Is the API simply broken:

https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines/{pipeline_uuid}/steps/{step_uuid}/log

Or am I missing something?

1 answer

1 accepted

0 votes
Answer accepted

I checked out the documentation of the corresponding REST API endpoint and they don't even list 406 as a possible response status code:

https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-pipeline-uuid-steps-step-uuid-log-get

If you're 100% sure that the two uuid's are correct and that they correctly replaced in the URL template (i.e. the final URL) is correct, then it may be a bug in Bitbucket.

If I were you, I'd try to send the same request, same URL, same headers from Postman to see if there is nothing obviously broken with it.

Ok... worked in Postman with the same (resolved) URL, so I checked for what else was different...

I was using the following headers:

headers = {"Accept": "application/json", "Authorization": f"Bearer {token}"}

.. which I stole from another request I was using - didn't respect that the fact that is was only accepting 'application/json' - my bad.

The docs don't specify a header at all, so I just didn't read them properly.

I changed the headers to:

headers = {"Accept": "*/*", "Authorization": f"Bearer {token}"}

.. and it now works perfectly.

Thanks for your help.

Like Aron Gombas _Midori_ likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events