- Notifications
You must be signed in to change notification settings - Fork1k
Open
Labels
Description
🚀 Feature Request
Submit the issue of duplicate key-value pairs in the form
Example
The data required by the server interface is as follows:test=1&test=2&test=3&mc=kaka
The implementation plan for sending requests is outlined below:
importrequestsresponse=requests.post(url='http://127.0.0.1:5000/form',verify=False,data={"test": ["1","2","3"],"mc":"kaka" })print(response.text)
It should be noted that Playwright does not natively support passing repeated key-value pairs, as they are escaped during serialization. To address this limitation, the following temporary solution has been implemented:
fromtypingimportOptional,List,Dictfromplaywright._impl._helperimportNameValuedefobject_to_array(obj:Optional[Dict])->Optional[List[NameValue]]:ifnotobj:returnNoneresult= []forkey,valueinobj.items():ifisinstance(value, (tuple,list)):forvinvalue:result.append(NameValue(name=key,value=str(v)))else:result.append(NameValue(name=key,value=str(value)))returnresult_helper.object_to_array=object_to_arrayfromplaywright.sync_apiimportsync_playwrightplaywright=sync_playwright().start()browser=playwright.chromium.launch()page=browser.new_page()response=page.request.post(url='http://127.0.0.1:5000/form',form={"test": ["1","2","3"],"mc":"kaka" })print(response.text)
Motivation
When encountering a duplicate key-value pair that needs to be submitted in the form in the interface