I am trying to upload a file to artifactory. I managed to do this successfully using the documentation with a curl call running in WSL2 based on this documented example:
curl -H "Authorization: Bearer <Token>" -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt" -T Desktop/myNewFile.txt
For various reasons (not having WSL2 on build server for example), I want to do this request from a python script. To understand how to upload a file using python, I used this as an example:
headers = {
'authorization': f"Bearer {token}"
}
files = {'upload_file': open('dummy9.txt', 'rb')}
print('Start the request')
response = requests.put(url, files=files, headers=headers)
print('Finished')
print(response.text)
This does not work. It gives an error message:
[SSL: WRONG_VERSION_NUMBER] wrong version number
In the curl call, I did not provide a version number. Logically, I also did not do that in the python script. This is because I want to do exactly the same call in the python web request as I did with the curl call. The curl call simply works fine. That is why I want the python script to do exactly the same. But in this case, it does not do that. Because it fails and the curl call succeeds.
I already found this question. The generally accepted answer is this. However, that is not working because because I do basically the same (except using a PUT instead of a POST) and it really gives an error while the curl call does not give an error.
So how to upload files with python in the same way that curl -T
does this?