1

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?

Daan
  • 2,478
  • 3
  • 36
  • 76
  • 1
    whoever marked this a duplicate of a question about POST clearly does not understand POST vs PUT – Daniel Stenberg Sep 07 '22 at 09:47
  • @DanielStenberg That is true. Moreover, the approach explained in the generally accepted answer https://stackoverflow.com/a/10234640/1987258 uses the same library and a similar call. I already explained that it is failing with an error message. – Daan Sep 07 '22 at 10:13
  • 1
    (voted to reopen for the reasons stated above) – Daniel Stenberg Sep 07 '22 at 11:37
  • I wonder about that -T also. I cannot find anywhere what the -T means. Is it a legitimate option? And when you send a file, do you not also need to also put a mime and content-type in the HTTP request header? The error message has noting to do with curl but will SSL. – Misunderstood Sep 08 '22 at 06:55

0 Answers0