我正在尝试查询 Adobe PDF 服务 API 以从 PDF 文档生成(导出)DOCX。
我刚刚编写了一个 python 代码来生成一个承载令牌,以便从Adobe PDF 服务中识别(请参阅此处的问题:https ://stackoverflow.com/questions/68351955/tunning-a-post-request-to-reach- adobe-pdf-services-using-python-and-a-rest-api)。然后我编写了以下代码,我尝试按照此页面中有关EXPORT
Adobe PDF 服务选项的说明进行操作(此处:https ://documentcloud.adobe.com/document-services/index.html#post-exportPDF )。
这是一段代码:
import requests
import json
from requests.structures import CaseInsensitiveDict
N/B:我没有编写生成令牌和启用服务器识别的代码部分
>> 这部分是通过表单参数上传我的 PDF 文件的 POST 请求
URL = "https://cpf-ue1.adobe.io/ops/:create?respondWith=%257B%2522reltype%2522%253A%2520%2522http%253A%252F%252Fns.adobe.com%252Frel%252Fprimary%2522%257D"
headers = CaseInsensitiveDict()
headers["x-api-key"] = "client_id"
headers["Authorization"] = "Bearer MYREALLYLONGTOKENIGOT"
headers["Content-Type"] = "application/json"
myfile = {"file":open("absolute_path_to_the_pdf_file/input.pdf", "rb")}
j="""
{
"cpf:engine": {
"repo:assetId": "urn:aaid:cpf:Service-26c7fda2890b44ad9a82714682e35888"
},
"cpf:inputs": {
"params": {
"cpf:inline": {
"targetFormat": "docx"
}
},
"documentIn": {
"dc:format": "application/pdf",
"cpf:location": "C:/Users/a-bensghir/Downloads/P_D_F/trs_pdf_file_copy.pdf"
}
},
"cpf:outputs": {
"documentOut": {
"dc:format": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"cpf:location": "C:/Users/a-bensghir/Downloads/P_D_F/output.docx"
}
}
}"""
resp = requests.post(url=URL, headers=headers, json=json.dumps(j), files=myfile)
print(resp.text)
print(resp.status_code)
代码的状态是400
我已经被服务器很好地验证了但是我得到以下结果print(resp.text)
:
{"requestId":"the_request_id","type":"Bad Request","title":"Not a multipart request. Aborting.","status":400,"report":"{\"error_code\":\"INVALID_MULTIPART_REQUEST\"}"}
我认为我无法理解 Adobe 指南中关于 API 的 EXPORT 作业的 POST 方法的“表单参数”(https://documentcloud.adobe.com/document-services/index.html)。
你有什么改进的想法吗?谢谢你 !