import requests import random,string from requeststoolbelt import MultipartEncoder…
- User
import requests import random,string from requests_toolbelt import MultipartEncoder
fields = { 'file': ('test.png', your_data, "image/png"), 'file_id': "0" } boundary = '----WebKitFormBoundary'
+ ''.join(random.sample(string.ascii_letters + string.digits, 16)) m = MultipartEncoder(fields=fields, boundary=boundary)headers = { "Host": "xxxx", "Connection": "keep-alive", "Content-Type": m.content_type }
req = requests.post('https://xxxx/api/upload', headers=headers, data=m)
but i also need this
payload = { "task": "post", "board": board, "thread": thread, "usercode": '', 'code':'', "captcha_type": "2chcaptcha", "email": '', "comment": comment, "oekaki_image": '', "oekaki_metadata": '', "2chcaptcha_value": captcha_answer, "2chcaptcha_id": captcha_id, 'makaka_id': '', 'makaka_answer': '',
}
- Assistant
To combine sending a file with additional payload data in a single POST request, you need to include your payload as fields in the
MultipartEncoder. Here's an example of how you can modify your current code to include the extra payload data along with the file upload:python