I had this query with with the requests library:
import requests
headers = {
    'Content-type': 'application/json',
}
data = """
{"target": {
  "ref_type": "branch",
  "type": "pipeline_ref_target",
  "ref_name": "main",
  "selector": {
    "type": "branches",
    "pattern" : "main"
    }
  }
}
"""
response = requests.post('https://api.bitbucket.org/2.0/repositories/name/{567899876}/pipelines/', headers=headers, data=data, auth=(username, password))
print(response.text)
Now, I want to do the same thing with the urllib.request or urllib3 preferably. I was trying this:
from urllib import request, parse
req =  request.Request('https://api.bitbucket.org/2.0/repositories/name/{4567898758}/pipelines/', method="POST", headers=headers, data=data, auth=(username, password))
resp = request.urlopen(req)
print(resp)
but urllib doesn't have an authparameter. I saw other examples online. For eg something like this:
auth_handler = url.HTTPBasicAuthHandler()
auth_handler.add_password(realm='Connect2Field API',
                          uri=urlp,
                          user='*****',
                          passwd='*****')
but I am not sure how to merge this with my existing headers in order to convert my request code to a urllib.request code.
