anonymous user A 302 response indicates a redirect. By default, the http.client
doesn't follow redirects I believe but using a package like requests should do the trick.
Azure python blob storage trigger run azure devops pipeline problem
현균 박
41
Reputation points
Hi.
I'm having a hard time for many days because of this problem.
I made Azure blob trigger(using python) for run Azure Devops Pipelines.
but it doesn't work.
It's a my code.
import logging
import base64
import http.client
import mimetypes
import azure.functions as func
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import pprint
def main(myblob: func.InputStream):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")
logging.info(f"start connect devops")
conn = http.client.HTTPSConnection("dev.azure.com")
body = "{\"previewRun\":false,\"stageToSkip=\": [],\"resources\": [], \"templateParameters\": [], \"variables\": []}"
pt = 'xvfnonij*************************wifjellqzjiqwa'
message_bytes = pt.encode('ascii')
base64_bytes = base64.b64encode(message_bytes)
base64_pat = base64_bytes.decode('ascii')
logging.info(f"pat: " + base64_pat)
headers = {
'Content-Type' : 'application/json',
'Accept' : 'application/json',
'Authorization' : 'Basic '+ base64_pat
}
logging.info(f"try connect devops")
url = "/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1"
logging.info(conn.request("POST", url, body, headers=headers))
res = conn.getresponse()
logging.info(res.msg)
logging.info(res.status)
data = res.read()
logging.info(f"finish connect devops")
I checked few links for this work.
- https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page#use-a-pat
- https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0
- https://stackoverflow.com/questions/66592742/how-to-solve-azure-devop-api-object-moved-result-in-python?noredirect=1#comment117725538_66592742
but my code's response was just 302 message.
I think.. 302 response is my oauth problem. however i used my PAT code from azure devops. also convert by base64.
Could you please let me know what the problem is?
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Accepted answer
-
Pramod Valavala 20,656 Reputation points Microsoft Employee Moderator
2021-03-15T16:12:07.5+00:00