saving UPS shipping labels

114 views
Skip to first unread message

Jim Gregory

unread,
Apr 19, 2013, 4:51:29 PM4/19/13
to web...@googlegroups.com
I'm working on a script to generate UPS shipping labels and save them on our server.  The shipping labels are passed as binary data in an XML file from UPS. I am using the ClassicUPS library to parse the XML file and save the data.

I wrote a simple script to test the library, and it works OK when I run it on the command line.  However, when I include the function to save the file in a controller, the saved files are corrupted.   If I use Imagemagick to read the file, it returns the error 'improper image header'.  The function in the library that saves the data is:

    def save_label(self, fd):
        raw_epl = self.accept_result.dict_response['ShipmentAcceptResponse']['ShipmentResults']['PackageResults']['LabelImage']['GraphicImage']
        binary = a2b_base64(raw_epl)
        fd.write(binary)

I call the function using:
    shipment.save_label(open('label.gif','wb'))

where shipment is a shipping label object produced by the library.

Does web2py do something that would corrupt the header?

Christian Foster Howes

unread,
Apr 25, 2013, 11:13:03 AM4/25/13
to web...@googlegroups.com
how are you setting self.accept_result.dict_response?  if it is request args or vars web2py does some checking to prevent various code injection attacks.  maybe that is mucking with your binary data?

Jim Gregory

unread,
May 17, 2013, 7:32:16 AM5/17/13
to web...@googlegroups.com
Just to follow up on this, I had not specified the file type in the function call and hence it did not encode it properly.  It works fine now.
Reply all
Reply to author
Forward
0 new messages