How to base64 encode a PDF file in Python

前端 未结 4 1044
天命终不由人
天命终不由人 2021-02-04 14:17

How should I base64 encode a PDF file for transport over XML-RPC in Python?

4条回答
  •  终归单人心
    2021-02-04 14:52

    Actually, after some more digging, it looks like the xmlrpclib module may have the piece I need with it's Binary helper class:

    binary_obj = xmlrpclib.Binary( open('foo.pdf').read() )
    

    Here's an example from the Trac XML-RPC documentation

    
    import xmlrpclib 
    server = xmlrpclib.ServerProxy("http://athomas:password@localhost:8080/trunk/login/xmlrpc") 
    server.wiki.putAttachment('WikiStart/t.py', xmlrpclib.Binary(open('t.py').read())) 
    

提交回复
热议问题