在使用pdf转word的时候通过文档中的方法,调用api,但是返回说AppNotExist,但实际是建好的

阅读次数 201
import hashlib
import http.client
from datetime import datetime
from email.utils import formatdate

conn = http.client.HTTPSConnection("solution.wps.cn")

payload = "{\"url\":\"https://arxiv.org/pdf/2309.08872.pdf\"}"
payload = payload.encode('utf-8')

now = datetime.now()
rfc1123_date = formatdate(timeval=now.timestamp(), localtime=False, usegmt=True)
url = "/api/developer/v1/office/pdf/convert/to/docx"

md5 = hashlib.md5()

# 更新md5对象
md5.update(payload)
md5_data = md5.hexdigest()

sha1 = hashlib.sha1()
app_key = "********************"
content_type = "application/json"
data = app_key + md5_data + content_type + rfc1123_date
# 更新sha1对象
sha1.update(data.encode('utf-8'))
sha1_data = sha1.hexdigest()

headers = {
    'Date': rfc1123_date,
    'Content-Md5': md5_data,
    'Content-Type': content_type,
    'Authorization': "WPS-2" + ":" + "**********" + ":" + sha1_data
}

conn.request("POST", url, payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

image.png

2 Answers

大佬,我们这边测试了一下测试应用是可以的。 js的签名代码参考如下:

const app_id = 'xxx'
const app_key = 'xxxx'

var method = pm.request.method

function signature(content_md5, date, content_type) {
  var str = app_key + content_md5 + content_type + date
  const hash = CryptoJS
    .SHA1(str).toString(CryptoJS.enc.Hex)

  return `WPS-2:${app_id}:${hash}`
}

var headers = pm.request.headers;

var url = "/api" + pm.request.url.toString().split("/api")[1]
var data = method === "GET" ? url : pm.request.body.raw ? pm.request.body.raw : url;
const content_md5 = CryptoJS.MD5(data).toString(CryptoJS.enc.Hex)
const date = new Date().toGMTString()

headers.add({
  key: "Content-type",
  value: "application/json",
});
headers.add({
  key: "Content-Md5",
  value: content_md5,
});
headers.add({
  key: "Date",
  value: date,
});
headers.add({
  key: "Authorization",
  value: signature(content_md5, date, 'application/json'),
});

还是上面的python代码,已经可以了

你的可以了么?我昨天建的应用也是这个问题.

应该可以了,非常抱歉,是我们这边有点小问题。

请确认创建的应用是否为格式转换应用。

是格式转换应用