如何从SoftLayer报价的二进制数据中获得 "PDF "文件?[英] How to get "PDF" file from the binary data of SoftLayer's quote?

本文是小编为大家收集整理的关于如何从SoftLayer报价的二进制数据中获得 "PDF "文件?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我通过SoftLayer的API的" GetPDF"获得了二进制数据.

参考. billingsoftlayer_billing_order_quote :: getpdf | SoftLayer开发网络 - getpdf

然后,我想从二进制数据创建PDF文件. 你知道如何进行吗?

推荐答案

该方法返回基本64中编码的二进制数据,您需要做的是解码二进制数据.

请参阅有关enconde和Decode二进制数据的本文.

https://code. tutsplus.com/tutorials/base64-coding-and-decoding-using-python-cms-25588

python客户端返回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()

本文地址:https://www.itbaoku.cn/post/1937818.html

问题描述

I got the binary data by "getPdf" method of SoftLayer's API.

Ref. BillingSoftLayer_Billing_Order_Quote::getPdf | SoftLayer Development Network - http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Order_Quote/getPdf

Then I wanna create the PDF file from the binary data. Do you know how to proceed it?

推荐答案

the method return a binary data encoded in base 64, what you need to do is decode the binary data.

see this article about enconde and decode binary data.

https://code.tutsplus.com/tutorials/base64-encoding-and-decoding-using-python--cms-25588

the Python client returns a xmlrpc.client.Binary object so you need to work with that object here an example using the Python client and 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)

Regards

其他推荐答案

This is my answer fo my question.

# 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()
相关标签/搜索