1

Im trying To Make post requests (multipart/form-data) in this website https://gofile.io/?t=api

every time time i got an error when i try to upload file

my code

import requests
req = requests.session()
files= {'file': open("test.txt", 'rb')}
response = req.post('https://srv-file7.gofile.io/upload', files=files)
print(response.text)

I got error every time ,are smething missing in the code

lou cjcj
  • 33
  • 5
  • Does this answer your question? [How to send a "multipart/form-data" with requests in python?](https://stackoverflow.com/questions/12385179/how-to-send-a-multipart-form-data-with-requests-in-python) – Carlos Horn Mar 06 '22 at 14:08

1 Answers1

1
from requests_toolbelt.multipart.encoder import MultipartEncoder
import requests
import json

mp_encoder = MultipartEncoder(
    fields={
        'filesUploaded': ('file_name.txt', open('file_name.txt', 'rb'))
    }
)
r = requests.post(
    'https://srv-file9.gofile.io/upload',
    data=mp_encoder,
    headers={'Content-Type': mp_encoder.content_type}
)
scrap = r.json()
# send "Token file" 123Abc
Token = scrap['data']['code']

Check this. It will work.

ouflak
  • 2,458
  • 10
  • 44
  • 49