通过剧作家 python apiContextRequest 的文件上传示例 [已关闭]

file upload example thru playwright python apiContextRequest [closed]

提问人:Vikash Patel 提问时间:11/16/2023 最后编辑:Vikash Patel 更新时间:11/17/2023 访问量:31

问:


编辑问题以包括所需的行为、特定问题或错误以及重现问题所需的最短代码。这将有助于其他人回答这个问题。

4天前关闭。

我有证书文件,我想通过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)
蟒蛇 剧作家

评论

1赞 eglease 11/16/2023
请将您的代码发布为文本而不是图像。
0赞 ggorlen 11/17/2023
这里没有剧作家代码。如果没有 和 ,这是不可重现的。 是无效的 Python 语法。请展示一个没有语法错误的最小可重现示例base_urltest.pemmulti-part=form_data
0赞 Vikash Patel 11/17/2023
@ggorlen 我无法添加完整的代码进行复制,因为它用于内部应用程序。所以基本上我需要示例来上传带有剧作家 python 的 POST 调用的文件

答: 暂无答案