I am trying to upload a csv file into Azure Devops workitem. While uploading the attachment step calling below rest api, I am facing an issue: POST https://dev.azure.com/{organization}/{project}/_apis/wit/attachments?api-version=5.1
My code is as below:
with open('details.csv', 'r') as f:
details = f.read()
print(details) #Printing the CSV file as expected
ado_req_headers_ATT = {'Content-Type':'application/octet-stream'}
ADO_SEC_ATTA_URL = 'https://dev.azure.com/orgname/projectname/_apis/wit/attachments?fileName=details.csv&api-version=5.1-preview.3'
ado_req_attach_File = requests.post(url=ADO_SEC_ATTA_URL,headers=ado_req_headers_ATT,data=details, auth=('',ADO_AUTH_PAT))
print(ado_req_attach_File.text)
Same code is working when I am using python 3.8 in my local visual studio code but not working when I am using Azure Automation Runbook (python 2.7).
When I try to print text of the response body, I am getting below error:
print(ado_req_attach_File.text)UnicodeEncodeError: 'ascii' codec can't encode character u'\u221e' in position 6303: ordinal not in range(128)
Expected Output:
{"id":"facedff6-48c6-5479-894b-f7807f29b96e","url":"https://dev.azure.com/orgname/d93740f8-fe37-5433-bc8e-79c0a320d81b/_apis/wit/attachments/facedff6-48c6-5479-894b-f7807f29b96e?fileName=details.csv"}