提问人:Vikash Patel 提问时间:11/16/2023 最后编辑:Vikash Patel 更新时间:11/17/2023 访问量:31
通过剧作家 python apiContextRequest 的文件上传示例 [已关闭]
file upload example thru playwright python apiContextRequest [closed]
问:
我有证书文件,我想通过apicontextRequest POST调用上传。但是我收到证书文件没有所需的换行符错误。但是同样的证书我可以通过网络上传,没有任何问题。我该如何解决?尝试使用以下来自 Playwright Docs 的代码:
The common way to send file(s) in the body of a request is to
upload them as form fields with multipart/form-data encoding.
You can achieve that with Playwright API like this:
api_request_context.post(
"https://example.com/api/uploadScrip'",
multipart={
"fileField": {
"name": "f.js",
"mimeType": "text/javascript",
"buffer": b"console.log(2022);",
},
})```
```python
url= f"{base_url}/certificate/upload"
with open("test.pem","rb") as f:
content= f.read()
multipart= {
"filePayload":{
"name": "test.pem",
"mimeType":"application/x-x509-ca-cert",
"buffer": content}
}
header= {"content-Type":"multipart/form-data"}
response= session.post(url=url,multipart=multipart,headers=header)
答: 暂无答案
评论
base_url
test.pem
multi-part=form_data