A
A
Arthas Leonidovich2020-08-17 17:07:44
Python
Arthas Leonidovich, 2020-08-17 17:07:44

Sending a multipart POST request with requests py to a router server?

You need to autonomously forward data to the router server.
By default, it accepts data using the POST method as a compound request, since the amount of data is quite large.
The request itself seems to be formed correctly, but when sending the file at a certain stage, an error occurs
{"success":false, "errorcode":"timeout"}
At the same time, the status code sent from the server is the 200th.
I can't figure out what is causing the timeout.

import requests
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from bs4 import BeautifulSoup





tx = open('D:\\Tmp\\Deco_E4_V1_1.1.1\\E4R 1.0_en_1.1.1 Build 20190917 Rel. 75120_US_EU_AU_up.bin', 'rb').read()
s = requests.Session()

url: str = 'http://192.168.68.1/cgi-bin/luci/;stok=4769e950ab5877c15ff7c0c7366bbe5f/admin/cloud?form=firmware'

headers1 = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
    'Content-Type': 'multipart/form-data; boundary=---------------------------303769881937665414043462042666',
    'Content-length': '12030960',
    'Origin': 'http://192.168.68.1',
    'Connection': 'keep-alive',
    'Referer': 'http://192.168.68.1/webpages/index.html',
    'Cookie': 'sysauth=ec769b12930cad93f4df73db56b256f5',
    'Upgrade-Insecure-Requests': '1',
}



r = requests.post(url, data=tx, headers=headers1,timeout = 2)
print(r.status_code)
print(r.text)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iddqda, 2020-08-18
@iddqda

'Content-length': '12030960'
timeout = 2
is 6Mb/s or almost 50Mb/s
, maybe the reason is that 12Mb doesn't have time to go over the network in 2 seconds or be taken by a dead router processor?
try removing timeout from request call

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question