I'm working with bitbucket pipelines to build and upload docker images automatically. We use AWS for our docker repo and they change their login credentials every 12 hours, so we need to retrieve and update the environment variables being used by bitbucket so that it can push the images to aws. I've written the following code using python requests to try to update the environment variables for docker user and password but am getting a "500 Internal Server Error" from bitbucket.
def update_pipeline_variable(uuid, name, value, token):
endpoint = 'https://api.bitbucket.com/2.0/repositories/myuser/myrepo/pipelines_config/variables/{{{variable_uuid}}}?access_token={token}'.format(
variable_uuid=uuid,
token=token
)
body = {
'value': value,
'key': name
}
headers = {"Authorization": "Bearer {token}".format(token=token)}
r = requests.put(endpoint, json=body, headers=headers)
if r.status_code == 200:
print('Successfully updated {variable_name} environment variable.'.format(variable_name=name))
return None
raise RuntimeError('The following error occurred while updating the environment: {error}'.format(error=r.content))
If I remove the access token from the request url and keep it only in the auth header, then I get a 404 instead of a 500. I know the tokens and uuids are valid because I am able to make the request successfully using Postman, so it's something specific to my python implementation. I also tried using the oauth2 requests library with exactly the same results.