Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

python - How to get "PDF" file from the binary data of SoftLayer's quote?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...