Azure python blob storage trigger run azure devops pipeline problem

현균 박 41 Reputation points
2021-03-15T07:42:11.103+00:00

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.

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.
4,637 questions
0 comments No comments
{count} votes

Accepted answer
  1. Pramod Valavala 20,611 Reputation points Microsoft Employee
    2021-03-15T16:12:07.5+00:00

    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.


1 additional answer

Sort by: Most helpful
  1. Vinay 1 Reputation point
    2021-12-22T07:09:35.503+00:00

    Kindly please share the working Code please. That will be helpfull. Please Share working code to this Mailid : theproblemslover8@Stuff .com or else share here only please.

    0 comments No comments