0

I need to upload a tar.gz file using python requests. When i try to check the payload in browser network tab i could see payload as below

------WebKitFormBoundary3sUg1Lq9ivT71NNI
Content-Disposition: form-data; name="file"; filename="cop-pem-cert.tar.gz"
Content-Type: application/gzip
------WebKitFormBoundary3sUg1Lq9ivT71NNI--

Any thoughts what should be the payload and headers to be used ? Tried this but getting 400

import requests
url='https://test.athena.com/data-migration/upload' 
headers={'referer': 'https://test.athena.com', 'cookie': 'i18next=; session=3c97e9d692670f6a_621662a4.JQXBkMr0-bDZiU2G4dZpoNP8m4A; csrftoken=##39d1b4f0a4b32898623f82c0033f1ebaa04ebd4d; hpeuck_cktst=','x-csrf-token':'##39d1b4f0a4b32898623f82c0033f1ebaa04ebd4d','X-Requested-With': 'XMLHttpRequest','Content-Type': 'application/gzip'}
a=requests.post(url,headers=headers,files={'file': ('cop-pem-cert.tar.gz', open('cop-pem-cert.tar.gz', 'rb'))})
asked Feb 24, 2022 at 10:32
2

1 Answer 1

1

In the headers we should not pass 'Content-Type': 'application/gzip' while doing post . After removing that it worked

Working code

>>> headers
{'referer': 'https://dummy.test.com', 'cookie': 'i18next=; session=17158f23bdd99dd1_62179b51.a2uP2cSYO_1ASd4fpfKuQaa2jtU; csrftoken=##1440ee62328990eadd4bb9d1bdf1f15bd6a973cb; hpeuck_cktst=', 'x-csrf-token': '##1440ee62328990eadd4bb9d1bdf1f15bd6a973cb', 'X-Requested-With': 'XMLHttpRequest'}
>>> files
{'file': ('cop-pem-cert.tar.gz', <_io.BufferedReader name='cop-pem-cert.tar.gz'>, 'application/gzip')}
>>> url
'https://dummy.test.com/data-migration/upload'
>>> a=requests.post(url,headers=headers,files=files)
>>> a=requests.post(url,headers=headers,files=files)
>>> a
<Response [200]>
answered Feb 28, 2022 at 14:59
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.