We are trying to automate some of the tasks of committing source code files to bitbucket repository. This will be done through a utility created in Python which will push some files (can be text/json etc) to a bitbucket repository.
As of now, tried using both Python Put and Post and get 405 and 415 error respectively.
Stash api used to post data-
https://stash.*****.com:8081/rest/api/1.0/projects/projectname/repos/reponame/browse/test.txt
Code snippet -
import requests,json
message=json.dumps({'content':open(filename,'r').read()})
request.put(url,auth=(username,password),headers={'content-type':'Application/json'},data=message,verify=False)
**filename is a text file, tried with json file also
Curl - Below Curl Command works perfectly fine from Unix, reads content from file.txt and copies it to new file test.txt -
curl -X PUT -u username:password -F content=@file.txt http://stash.*****.com/rest/api/1.0/projects/PROJECT_1/projectname/repos/reponame/browse/test.txt
Referenced below documentation-
https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm8297049152
Please suggest what is missing in python code. Why are we continuously getting 415 error?
Also, is there a better way to achieve source code management automation via Python? Any other rest api/Python library which can do the job better?