如何从 SoftLayer 报价的二进制数据中获取 "PDF" 文件?
How to get "PDF" file from the binary data of SoftLayer's quote?
我通过SoftLayerAPI的"getPdf"方法得到了二进制数据。
参考。
BillingSoftLayer_Billing_Order_Quote::getPdf | SoftLayer 开发网络 - http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Order_Quote/getPdf
然后我想从二进制数据创建 PDF 文件。
你知道如何进行吗?
方法return一个用base 64编码的二进制数据,你需要做的就是解码二进制数据。
请参阅这篇关于编码和解码二进制数据的文章。
https://code.tutsplus.com/tutorials/base64-encoding-and-decoding-using-python--cms-25588
Python 客户端 return 是一个 xmlrpc.client.Binary 对象,因此您需要在此处使用该对象作为使用 Python 客户端和 Python 3 的示例
#!/usr/bin/env python
import SoftLayer
import xmlrpc.client
import base64
import os
USERNAME = 'set me'
API_KEY = 'set me'
quoteId = 1560845
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountClient = client['SoftLayer_Billing_Order_Quote']
binaryData = accountClient.getPdf(id=quoteId)
decodeBinary = binaryData.data
file = open('test.pdf','wb')
file.write(decodeBinary)
此致
这是我对问题的回答。
# import
import SoftLayer
import sys
parm=sys.argv
quoteId=parm[1]
# account info
client = SoftLayer.create_client_from_env()
# getPdf as a binary data
getPdf = client['Billing_Order_Quote'].getPdf(id=quoteId)
# Save as a PDF
quoteFileName = "Quote_ID_%s.pdf" % quoteId
w = open(quoteFileName, "wb")
w.write(getPdf.data)
w.close()
我通过SoftLayerAPI的"getPdf"方法得到了二进制数据。
参考。 BillingSoftLayer_Billing_Order_Quote::getPdf | SoftLayer 开发网络 - http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Order_Quote/getPdf
然后我想从二进制数据创建 PDF 文件。 你知道如何进行吗?
方法return一个用base 64编码的二进制数据,你需要做的就是解码二进制数据。
请参阅这篇关于编码和解码二进制数据的文章。
https://code.tutsplus.com/tutorials/base64-encoding-and-decoding-using-python--cms-25588
Python 客户端 return 是一个 xmlrpc.client.Binary 对象,因此您需要在此处使用该对象作为使用 Python 客户端和 Python 3 的示例
#!/usr/bin/env python
import SoftLayer
import xmlrpc.client
import base64
import os
USERNAME = 'set me'
API_KEY = 'set me'
quoteId = 1560845
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountClient = client['SoftLayer_Billing_Order_Quote']
binaryData = accountClient.getPdf(id=quoteId)
decodeBinary = binaryData.data
file = open('test.pdf','wb')
file.write(decodeBinary)
此致
这是我对问题的回答。
# import
import SoftLayer
import sys
parm=sys.argv
quoteId=parm[1]
# account info
client = SoftLayer.create_client_from_env()
# getPdf as a binary data
getPdf = client['Billing_Order_Quote'].getPdf(id=quoteId)
# Save as a PDF
quoteFileName = "Quote_ID_%s.pdf" % quoteId
w = open(quoteFileName, "wb")
w.write(getPdf.data)
w.close()