How to get PDF file from the binary data of SoftLayers quote?

2024/11/18 2:54:33

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?

Answer

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 pythonimport SoftLayer
import xmlrpc.client
import base64
import osUSERNAME = 'set me'
API_KEY = 'set me'quoteId = 1560845client = 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

https://en.xdnf.cn/q/120127.html

Related Q&A

How to list of elements and use those elements as a header of pandas dataframe?

I have a list with some elements. For example: list= [name, phone_number,age,gender] I want to use these elements as a header or column name in a pandas dataframe. I would really appreciate your ideas.…

Averaging Filter using python

I am new in python and trying apply averaging filter on image as the way i understand averaging concept summing up the neighboring elements including itself and divide it by number of elementstechnique…

Click on Show more deals in webpage with Selenium

Id like to click on every Show 10 more deals on the following page: "https://www.uswitch.com/broadband/compare/deals_and_offers/" but it does not seem to work. Im stuck having the following e…

In Matplotlib, what axis attribute specifies the spacing between ticks? [duplicate]

This question already has answers here:Changing the tick frequency on the x or y axis(15 answers)Closed 6 years ago.When generating a Matplotlib line or scatter plot, what axis attribute specifies the …

How can I make a simple calculator in python 3?

Im making this calculator using python 3, and this is what I have so far:print("Welcome to Calculator!")class Calculator:def addition(self,x,y):added = x + yreturn addeddef subtraction(self,x…

python 3: lists dont change their values

So I am trying to change a bunch of list items by a random percentage using a for loop.import random as rdm list = [1000, 100, 50, 25] def change():for item in list:item = item + item*rdm.uniform(-10, …

Using zip_longest on unequal lists but repeat the last entry instead of returning None

There is an existing thread about this Zipping unequal lists in python in to a list which does not drop any element from longer list being zipped But its not quite Im after. Instead of returning None, …

python scrapy not crawling all urls in scraped list

I am trying to scrape information from the pages listed on this page. https://pardo.ch/pardo/program/archive/2017/catalog-films.htmlthe xpath selector:film_page_urls_startpage = sel.xpath(//article[@cl…

Python - Do (something) when event is near [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Python script to find nth prime number

Im new to Python and I thought Id try to learn the ropes a bit by writing a function to find the nth prime number, however I cant get my code to work properly. No doubt this is due to me missing someth…